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