@@ -946,7 +946,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
946
946
buf -> st_uid = 0 ;
947
947
buf -> st_nlink = 1 ;
948
948
buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
949
- findbuf .dwReserved0 );
949
+ findbuf .dwReserved0 , file_name );
950
950
buf -> st_size = S_ISLNK (buf -> st_mode ) ? MAX_LONG_PATH :
951
951
fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
952
952
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -997,7 +997,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
997
997
buf -> st_gid = 0 ;
998
998
buf -> st_uid = 0 ;
999
999
buf -> st_nlink = 1 ;
1000
- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
1000
+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
1001
1001
buf -> st_size = fdata .nFileSizeLow |
1002
1002
(((off_t )fdata .nFileSizeHigh )<<32 );
1003
1003
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -2260,6 +2260,13 @@ int mingw_rename(const char *pold, const char *pnew)
2260
2260
return 0 ;
2261
2261
gle = GetLastError ();
2262
2262
2263
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2264
+ /* Fall back to copy to destination & remove source */
2265
+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2266
+ return 0 ;
2267
+ gle = GetLastError ();
2268
+ }
2269
+
2263
2270
/* revert file attributes on failure */
2264
2271
if (attrs != INVALID_FILE_ATTRIBUTES )
2265
2272
SetFileAttributesW (wpnew , attrs );
@@ -3215,3 +3222,62 @@ const char *program_data_config(void)
3215
3222
}
3216
3223
return * path .buf ? path .buf : NULL ;
3217
3224
}
3225
+
3226
+ /*
3227
+ * Based on https://stackoverflow.com/questions/43002803
3228
+ *
3229
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3230
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3231
+ * "ErrorControl"=dword:00000001
3232
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3233
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3234
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3235
+ * 65,00,00,00
3236
+ * "Start"=dword:00000002
3237
+ * "Type"=dword:00000010
3238
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3239
+ * "ObjectName"="LocalSystem"
3240
+ * "ServiceSidType"=dword:00000001
3241
+ */
3242
+ int is_inside_windows_container (void )
3243
+ {
3244
+ static int inside_container = -1 ; /* -1 uninitialized */
3245
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
3246
+ HKEY handle = NULL ;
3247
+
3248
+ if (inside_container != -1 )
3249
+ return inside_container ;
3250
+
3251
+ inside_container = ERROR_SUCCESS ==
3252
+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
3253
+ RegCloseKey (handle );
3254
+
3255
+ return inside_container ;
3256
+ }
3257
+
3258
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
3259
+ {
3260
+ int fMode = S_IREAD ;
3261
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
3262
+ tag == IO_REPARSE_TAG_SYMLINK ) {
3263
+ int flag = S_IFLNK ;
3264
+ char buf [MAX_LONG_PATH ];
3265
+
3266
+ /*
3267
+ * Windows containers' mapped volumes are marked as reparse
3268
+ * points and look like symbolic links, but they are not.
3269
+ */
3270
+ if (path && is_inside_windows_container () &&
3271
+ readlink (path , buf , sizeof (buf )) > 27 &&
3272
+ starts_with (buf , "/ContainerMappedDirectories/" ))
3273
+ flag = S_IFDIR ;
3274
+
3275
+ fMode |= flag ;
3276
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
3277
+ fMode |= S_IFDIR ;
3278
+ else
3279
+ fMode |= S_IFREG ;
3280
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
3281
+ fMode |= S_IWRITE ;
3282
+ return fMode ;
3283
+ }
0 commit comments