Diff
Not logged in

Differences From Artifact [8263f108df]:

To Artifact [a4be4f45df]:


63
64
65
66
67
68
69
70

71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92



93


94
95
96
97
98
99
100
63
64
65
66
67
68
69

70
71
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103
104







-
+


-
+



















+
+
+
-
+
+







#endif /* INTERFACE */

#if !defined(_WIN32) || !(defined(__MSVCRT__) || defined(_MSC_VER))
# define fossilStat stat
#endif

/*
** On Windows S_ISLNK always returns FALSE.
** On Windows S_ISLNK can be true or false.
*/
#if !defined(S_ISLNK)
# define S_ISLNK(x) (0)
# define S_ISLNK(x) ((x)==S_IFLNK)
#endif
static int fileStatValid = 0;
static struct fossilStat fileStat;

/*
** Fill stat buf with information received from stat() or lstat().
** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
**
*/
static int fossil_stat(const char *zFilename, struct fossilStat *buf, int isWd){
  int rc;
  void *zMbcs = fossil_utf8_to_filename(zFilename);
#if !defined(_WIN32)
  if( isWd && g.allowSymlinks ){
    rc = lstat(zMbcs, buf);
  }else{
    rc = stat(zMbcs, buf);
  }
#else
  if( isWd && g.allowSymlinks ){
    rc = win32_lstat(zMbcs, buf);
  }else{
  rc = win32_stat(zMbcs, buf, isWd);
    rc = win32_stat(zMbcs, buf);
  }
#endif
  fossil_filename_free(zMbcs);
  return rc;
}

/*
** Fill in the fileStat variable for the file named zFilename.
182
183
184
185
186
187
188




189

190
191
192
193
194
195
196
186
187
188
189
190
191
192
193
194
195
196

197
198
199
200
201
202
203
204







+
+
+
+
-
+







** Create symlink to file on Unix, or plain-text file with
** symlink target if "allow-symlinks" is off or we're on Windows.
**
** Arguments: target file (symlink will point to it), link file
**/
void symlink_create(const char *zTargetFile, const char *zLinkFile){
#if !defined(_WIN32)
  int symlinks_supported = 1;
#else
  int symlinks_supported = win32_symlinks_supported(zLinkFile);
#endif
  if( g.allowSymlinks ){
  if( symlinks_supported && g.allowSymlinks ){
    int i, nName;
    char *zName, zBuf[1000];

    nName = strlen(zLinkFile);
    if( nName>=sizeof(zBuf) ){
      zName = mprintf("%s", zLinkFile);
    }else{
204
205
206
207
208
209
210

211





212
213
214
215

216
217
218
219
220
221
222
223
224
212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
227

228


229
230
231
232
233
234
235







+
-
+
+
+
+
+



-
+
-
-







          if( file_mkdir(zName, 1) ){
            fossil_fatal_recursive("unable to create directory %s", zName);
            return;
          }
        zName[i] = '/';
      }
    }
#if !defined(_WIN32)
    if( symlink(zTargetFile, zName)!=0 ){
    if( symlink(zTargetFile, zName)!=0 )
#else
    if( win32_symlink(zTargetFile, zName)!=0 )
#endif
    {
      fossil_fatal_recursive("unable to create symlink \"%s\"", zName);
    }
    if( zName!=zBuf ) free(zName);
  }else
  }else{
#endif
  {
    Blob content;
    blob_set(&content, zTargetFile);
    blob_write_to_file(&content, zLinkFile);
    blob_reset(&content);
  }
}

241
242
243
244
245
246
247
248
249
250
251
252
253

254
255
256
257
258
259
260
261
262
263
264
265
266
252
253
254
255
256
257
258



259
260
261
262
263
264
265
266
267

268
269
270
271
272
273
274







-
-
-



+





-







int file_wd_perm(const char *zFilename){
  if( getStat(zFilename, 1) ) return PERM_REG;
#if defined(_WIN32)
#  ifndef S_IXUSR
#    define S_IXUSR  _S_IEXEC
#  endif
  if( S_ISREG(fileStat.st_mode) && ((S_IXUSR)&fileStat.st_mode)!=0 )
    return PERM_EXE;
  else
    return PERM_REG;
#else
  if( S_ISREG(fileStat.st_mode) &&
      ((S_IXUSR|S_IXGRP|S_IXOTH)&fileStat.st_mode)!=0 )
#endif
    return PERM_EXE;
  else if( g.allowSymlinks && S_ISLNK(fileStat.st_mode) )
    return PERM_LNK;
  else
    return PERM_REG;
#endif
}

/*
** Return TRUE if the named file is an executable.  Return false
** for directories, devices, fifos, symlinks, etc.
*/
int file_wd_isexe(const char *zFilename){