@@ -1123,7 +1123,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
1123
1123
buf -> st_uid = 0 ;
1124
1124
buf -> st_nlink = 1 ;
1125
1125
buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
1126
- reparse_tag );
1126
+ reparse_tag , file_name );
1127
1127
buf -> st_size = S_ISLNK (buf -> st_mode ) ? link_len :
1128
1128
fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
1129
1129
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -1174,7 +1174,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
1174
1174
buf -> st_gid = 0 ;
1175
1175
buf -> st_uid = 0 ;
1176
1176
buf -> st_nlink = 1 ;
1177
- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
1177
+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
1178
1178
buf -> st_size = fdata .nFileSizeLow |
1179
1179
(((off_t )fdata .nFileSizeHigh )<<32 );
1180
1180
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -2768,6 +2768,13 @@ int mingw_rename(const char *pold, const char *pnew)
2768
2768
gle = GetLastError ();
2769
2769
}
2770
2770
2771
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2772
+ /* Fall back to copy to destination & remove source */
2773
+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2774
+ return 0 ;
2775
+ gle = GetLastError ();
2776
+ }
2777
+
2771
2778
/* revert file attributes on failure */
2772
2779
if (attrs != INVALID_FILE_ATTRIBUTES )
2773
2780
SetFileAttributesW (wpnew , attrs );
@@ -4186,3 +4193,62 @@ int mingw_have_unix_sockets(void)
4186
4193
return ret ;
4187
4194
}
4188
4195
#endif
4196
+
4197
+ /*
4198
+ * Based on https://stackoverflow.com/questions/43002803
4199
+ *
4200
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
4201
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
4202
+ * "ErrorControl"=dword:00000001
4203
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
4204
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
4205
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
4206
+ * 65,00,00,00
4207
+ * "Start"=dword:00000002
4208
+ * "Type"=dword:00000010
4209
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
4210
+ * "ObjectName"="LocalSystem"
4211
+ * "ServiceSidType"=dword:00000001
4212
+ */
4213
+ int is_inside_windows_container (void )
4214
+ {
4215
+ static int inside_container = -1 ; /* -1 uninitialized */
4216
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
4217
+ HKEY handle = NULL ;
4218
+
4219
+ if (inside_container != -1 )
4220
+ return inside_container ;
4221
+
4222
+ inside_container = ERROR_SUCCESS ==
4223
+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
4224
+ RegCloseKey (handle );
4225
+
4226
+ return inside_container ;
4227
+ }
4228
+
4229
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
4230
+ {
4231
+ int fMode = S_IREAD ;
4232
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
4233
+ tag == IO_REPARSE_TAG_SYMLINK ) {
4234
+ int flag = S_IFLNK ;
4235
+ char buf [MAX_LONG_PATH ];
4236
+
4237
+ /*
4238
+ * Windows containers' mapped volumes are marked as reparse
4239
+ * points and look like symbolic links, but they are not.
4240
+ */
4241
+ if (path && is_inside_windows_container () &&
4242
+ readlink (path , buf , sizeof (buf )) > 27 &&
4243
+ starts_with (buf , "/ContainerMappedDirectories/" ))
4244
+ flag = S_IFDIR ;
4245
+
4246
+ fMode |= flag ;
4247
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
4248
+ fMode |= S_IFDIR ;
4249
+ else
4250
+ fMode |= S_IFREG ;
4251
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
4252
+ fMode |= S_IWRITE ;
4253
+ return fMode ;
4254
+ }
0 commit comments