@@ -1122,7 +1122,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
1122
1122
buf -> st_uid = 0 ;
1123
1123
buf -> st_nlink = 1 ;
1124
1124
buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
1125
- reparse_tag );
1125
+ reparse_tag , file_name );
1126
1126
buf -> st_size = S_ISLNK (buf -> st_mode ) ? link_len :
1127
1127
fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
1128
1128
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -1173,7 +1173,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
1173
1173
buf -> st_gid = 0 ;
1174
1174
buf -> st_uid = 0 ;
1175
1175
buf -> st_nlink = 1 ;
1176
- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
1176
+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
1177
1177
buf -> st_size = fdata .nFileSizeLow |
1178
1178
(((off_t )fdata .nFileSizeHigh )<<32 );
1179
1179
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -2815,6 +2815,13 @@ int mingw_rename(const char *pold, const char *pnew)
2815
2815
gle = GetLastError ();
2816
2816
}
2817
2817
2818
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2819
+ /* Fall back to copy to destination & remove source */
2820
+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2821
+ return 0 ;
2822
+ gle = GetLastError ();
2823
+ }
2824
+
2818
2825
/* revert file attributes on failure */
2819
2826
if (attrs != INVALID_FILE_ATTRIBUTES )
2820
2827
SetFileAttributesW (wpnew , attrs );
@@ -4222,3 +4229,62 @@ int mingw_have_unix_sockets(void)
4222
4229
return ret ;
4223
4230
}
4224
4231
#endif
4232
+
4233
+ /*
4234
+ * Based on https://stackoverflow.com/questions/43002803
4235
+ *
4236
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
4237
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
4238
+ * "ErrorControl"=dword:00000001
4239
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
4240
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
4241
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
4242
+ * 65,00,00,00
4243
+ * "Start"=dword:00000002
4244
+ * "Type"=dword:00000010
4245
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
4246
+ * "ObjectName"="LocalSystem"
4247
+ * "ServiceSidType"=dword:00000001
4248
+ */
4249
+ int is_inside_windows_container (void )
4250
+ {
4251
+ static int inside_container = -1 ; /* -1 uninitialized */
4252
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
4253
+ HKEY handle = NULL ;
4254
+
4255
+ if (inside_container != -1 )
4256
+ return inside_container ;
4257
+
4258
+ inside_container = ERROR_SUCCESS ==
4259
+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
4260
+ RegCloseKey (handle );
4261
+
4262
+ return inside_container ;
4263
+ }
4264
+
4265
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
4266
+ {
4267
+ int fMode = S_IREAD ;
4268
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
4269
+ tag == IO_REPARSE_TAG_SYMLINK ) {
4270
+ int flag = S_IFLNK ;
4271
+ char buf [MAX_LONG_PATH ];
4272
+
4273
+ /*
4274
+ * Windows containers' mapped volumes are marked as reparse
4275
+ * points and look like symbolic links, but they are not.
4276
+ */
4277
+ if (path && is_inside_windows_container () &&
4278
+ readlink (path , buf , sizeof (buf )) > 27 &&
4279
+ starts_with (buf , "/ContainerMappedDirectories/" ))
4280
+ flag = S_IFDIR ;
4281
+
4282
+ fMode |= flag ;
4283
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
4284
+ fMode |= S_IFDIR ;
4285
+ else
4286
+ fMode |= S_IFREG ;
4287
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
4288
+ fMode |= S_IWRITE ;
4289
+ return fMode ;
4290
+ }
0 commit comments