Diff
Not logged in

Differences From Artifact [a4d5d369ed]:

To Artifact [4305abcef2]:


88
89
90
91
92
93
94
95
96
97
98
99




100
101
102
103
104
105
106
      tlen = win32_readlink(tname, tlink, sizeof(tlink));
      fossil_filename_free(tname);
    }
    
    ULARGE_INTEGER ull;

    /* if a link was retrieved, it is a symlink, otherwise a dir or file */
    buf->st_mode = (tlen > 0) ? S_IFLNK :
                   ((attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ?
                     S_IFDIR : S_IFREG);
    
    buf->st_size = (((i64)attr.nFileSizeHigh)<<32) | attr.nFileSizeLow;




    
    ull.LowPart = attr.ftLastWriteTime.dwLowDateTime;
    ull.HighPart = attr.ftLastWriteTime.dwHighDateTime;
    buf->st_mtime = ull.QuadPart / 10000000ULL - 11644473600ULL;
  }
  return !rc;
}







|
|
|

|
>
>
>
>







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
      tlen = win32_readlink(tname, tlink, sizeof(tlink));
      fossil_filename_free(tname);
    }
    
    ULARGE_INTEGER ull;

    /* if a link was retrieved, it is a symlink, otherwise a dir or file */
    if (tlen == 0){
      buf->st_mode = ((attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ?
                       S_IFDIR : S_IFREG);
    
      buf->st_size = (((i64)attr.nFileSizeHigh)<<32) | attr.nFileSizeLow;
    }else{
      buf->st_mode = S_IFLNK;
      buf->st_size = tlen;
    }
    
    ull.LowPart = attr.ftLastWriteTime.dwLowDateTime;
    ull.HighPart = attr.ftLastWriteTime.dwHighDateTime;
    buf->st_mtime = ull.QuadPart / 10000000ULL - 11644473600ULL;
  }
  return !rc;
}
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
    rc = win32_lstat(zFilename, buf);

    /* exit on error or not link */
    if ((rc != 0) || (buf->st_mode != S_IFLNK))
      break;

    /* it is a link, so open the linked file */      
    file = CreateFileW(zFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
    if ((file == NULL) || (file == INVALID_HANDLE_VALUE)){
      rc = 1;
      break;
    }

    /* get the final path name and close the handle */
    len = GetFinalPathNameByHandleW(file, nextFilename, LINK_BUFFER_SIZE - 1, 0);







|







130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    rc = win32_lstat(zFilename, buf);

    /* exit on error or not link */
    if ((rc != 0) || (buf->st_mode != S_IFLNK))
      break;

    /* it is a link, so open the linked file */      
    file = CreateFileW(zFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
    if ((file == NULL) || (file == INVALID_HANDLE_VALUE)){
      rc = 1;
      break;
    }

    /* get the final path name and close the handle */
    len = GetFinalPathNameByHandleW(file, nextFilename, LINK_BUFFER_SIZE - 1, 0);
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
  
  /* does path reference a reparse point? */
  WIN32_FILE_ATTRIBUTE_DATA attr;
  int rc = GetFileAttributesEx(path, GetFileExInfoStandard, &attr);
  if (rc && (attr.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)){
  
    /* since it is a reparse point, open it */
    HANDLE file = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 
      FILE_FLAG_OPEN_REPARSE_POINT, NULL);      
    if ((file != NULL) && (file != INVALID_HANDLE_VALUE)){

      /* use DeviceIoControl to get the reparse point data */
    
      int data_size = sizeof(REPARSE_DATA_BUFFER) + LINK_BUFFER_SIZE * sizeof(wchar_t);
      REPARSE_DATA_BUFFER* data = fossil_malloc(data_size);
      DWORD data_used;







|
|







169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
  
  /* does path reference a reparse point? */
  WIN32_FILE_ATTRIBUTE_DATA attr;
  int rc = GetFileAttributesEx(path, GetFileExInfoStandard, &attr);
  if (rc && (attr.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)){
  
    /* since it is a reparse point, open it */
    HANDLE file = CreateFile(path, FILE_READ_EA, 0, NULL, OPEN_EXISTING, 
      FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL);      
    if ((file != NULL) && (file != INVALID_HANDLE_VALUE)){

      /* use DeviceIoControl to get the reparse point data */
    
      int data_size = sizeof(REPARSE_DATA_BUFFER) + LINK_BUFFER_SIZE * sizeof(wchar_t);
      REPARSE_DATA_BUFFER* data = fossil_malloc(data_size);
      DWORD data_used;
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
** files and for directories. Thus you must unlink a file symlink or rmdir a
** directory symlink. This is a convenience function used when we know we're
** deleting a symlink of some type.
** Returns 0 on success, 1 on failure.
*/
int win32_unlink_rmdir(const wchar_t *zFilename){
  int rc = 0;
  fossilStat stat;
  if (win32_stat(zFilename, &stat) == 0){
    if (stat.st_mode == S_IFDIR)
      rc = RemoveDirectoryW(zFilename);
    else
      rc = DeleteFileW(zFilename);
  }
  return !rc;
}








|
|
|







225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
** files and for directories. Thus you must unlink a file symlink or rmdir a
** directory symlink. This is a convenience function used when we know we're
** deleting a symlink of some type.
** Returns 0 on success, 1 on failure.
*/
int win32_unlink_rmdir(const wchar_t *zFilename){
  int rc = 0;
  WIN32_FILE_ATTRIBUTE_DATA attr;
  if (GetFileAttributesExW(zFilename, GetFileExInfoStandard, &attr)){
    if ((attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
      rc = RemoveDirectoryW(zFilename);
    else
      rc = DeleteFileW(zFilename);
  }
  return !rc;
}

272
273
274
275
276
277
278
























279
280
281
282
283
284
285
    blob_write_to_file(&content, newpath);
    blob_reset(&content);
    created = 1;
  }
  
  return !created;
}

























/*
** Check if symlinks are potentially supported on the current OS for the given file.
** Theoretically this code should work on any NT based version of windows
** but I have no way of testing that. The initial check for
** IsWindowsVistaOrGreater() should in theory eliminate any system prior to
** Windows Vista, but I have no way to test that at this time.







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
    blob_write_to_file(&content, newpath);
    blob_reset(&content);
    created = 1;
  }
  
  return !created;
}

/*
** Given a pathname to a file, return true if:
**   1. the file exists
**   2. the file is a symbolic link
**   3. the symbolic link's attributes can be acquired
**   4. the symbolic link type is different than the target type
*/
int win32_check_symlink_type_changed(const char* zName){
  int changed = 0;
  wchar_t* zMbcs;
  fossilStat lstat_buf, stat_buf;
  WIN32_FILE_ATTRIBUTE_DATA lstat_attr;
  zMbcs = fossil_utf8_to_filename(zName);
  if (win32_stat(zMbcs, &stat_buf) != 0)
    stat_buf.st_mode = S_IFREG;
  changed =
    (win32_lstat(zMbcs, &lstat_buf) == 0) &&
    (lstat_buf.st_mode == S_IFLNK) &&
    GetFileAttributesExW(zMbcs, GetFileExInfoStandard, &lstat_attr) &&
    ((stat_buf.st_mode == S_IFDIR) != ((lstat_attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY));
  fossil_filename_free(zMbcs);
  return changed;
}

/*
** Check if symlinks are potentially supported on the current OS for the given file.
** Theoretically this code should work on any NT based version of windows
** but I have no way of testing that. The initial check for
** IsWindowsVistaOrGreater() should in theory eliminate any system prior to
** Windows Vista, but I have no way to test that at this time.