@@ -1148,7 +1148,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
1148
1148
buf -> st_uid = 0 ;
1149
1149
buf -> st_nlink = 1 ;
1150
1150
buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
1151
- reparse_tag );
1151
+ reparse_tag , file_name );
1152
1152
buf -> st_size = S_ISLNK (buf -> st_mode ) ? link_len :
1153
1153
fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
1154
1154
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -1199,7 +1199,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
1199
1199
buf -> st_gid = 0 ;
1200
1200
buf -> st_uid = 0 ;
1201
1201
buf -> st_nlink = 1 ;
1202
- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
1202
+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
1203
1203
buf -> st_size = fdata .nFileSizeLow |
1204
1204
(((off_t )fdata .nFileSizeHigh )<<32 );
1205
1205
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -2793,6 +2793,13 @@ int mingw_rename(const char *pold, const char *pnew)
2793
2793
gle = GetLastError ();
2794
2794
}
2795
2795
2796
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2797
+ /* Fall back to copy to destination & remove source */
2798
+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2799
+ return 0 ;
2800
+ gle = GetLastError ();
2801
+ }
2802
+
2796
2803
/* revert file attributes on failure */
2797
2804
if (attrs != INVALID_FILE_ATTRIBUTES )
2798
2805
SetFileAttributesW (wpnew , attrs );
@@ -4234,3 +4241,62 @@ int mingw_have_unix_sockets(void)
4234
4241
return ret ;
4235
4242
}
4236
4243
#endif
4244
+
4245
+ /*
4246
+ * Based on https://stackoverflow.com/questions/43002803
4247
+ *
4248
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
4249
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
4250
+ * "ErrorControl"=dword:00000001
4251
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
4252
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
4253
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
4254
+ * 65,00,00,00
4255
+ * "Start"=dword:00000002
4256
+ * "Type"=dword:00000010
4257
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
4258
+ * "ObjectName"="LocalSystem"
4259
+ * "ServiceSidType"=dword:00000001
4260
+ */
4261
+ int is_inside_windows_container (void )
4262
+ {
4263
+ static int inside_container = -1 ; /* -1 uninitialized */
4264
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
4265
+ HKEY handle = NULL ;
4266
+
4267
+ if (inside_container != -1 )
4268
+ return inside_container ;
4269
+
4270
+ inside_container = ERROR_SUCCESS ==
4271
+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
4272
+ RegCloseKey (handle );
4273
+
4274
+ return inside_container ;
4275
+ }
4276
+
4277
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
4278
+ {
4279
+ int fMode = S_IREAD ;
4280
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
4281
+ tag == IO_REPARSE_TAG_SYMLINK ) {
4282
+ int flag = S_IFLNK ;
4283
+ char buf [MAX_LONG_PATH ];
4284
+
4285
+ /*
4286
+ * Windows containers' mapped volumes are marked as reparse
4287
+ * points and look like symbolic links, but they are not.
4288
+ */
4289
+ if (path && is_inside_windows_container () &&
4290
+ readlink (path , buf , sizeof (buf )) > 27 &&
4291
+ starts_with (buf , "/ContainerMappedDirectories/" ))
4292
+ flag = S_IFDIR ;
4293
+
4294
+ fMode |= flag ;
4295
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
4296
+ fMode |= S_IFDIR ;
4297
+ else
4298
+ fMode |= S_IFREG ;
4299
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
4300
+ fMode |= S_IWRITE ;
4301
+ return fMode ;
4302
+ }
0 commit comments