@@ -1027,7 +1027,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
1027
1027
buf -> st_uid = 0 ;
1028
1028
buf -> st_nlink = 1 ;
1029
1029
buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
1030
- reparse_tag );
1030
+ reparse_tag , file_name );
1031
1031
buf -> st_size = S_ISLNK (buf -> st_mode ) ? link_len :
1032
1032
fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
1033
1033
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -1078,7 +1078,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
1078
1078
buf -> st_gid = 0 ;
1079
1079
buf -> st_uid = 0 ;
1080
1080
buf -> st_nlink = 1 ;
1081
- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
1081
+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
1082
1082
buf -> st_size = fdata .nFileSizeLow |
1083
1083
(((off_t )fdata .nFileSizeHigh )<<32 );
1084
1084
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -2550,6 +2550,13 @@ int mingw_rename(const char *pold, const char *pnew)
2550
2550
return 0 ;
2551
2551
gle = GetLastError ();
2552
2552
2553
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2554
+ /* Fall back to copy to destination & remove source */
2555
+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2556
+ return 0 ;
2557
+ gle = GetLastError ();
2558
+ }
2559
+
2553
2560
/* revert file attributes on failure */
2554
2561
if (attrs != INVALID_FILE_ATTRIBUTES )
2555
2562
SetFileAttributesW (wpnew , attrs );
@@ -3882,3 +3889,62 @@ int uname(struct utsname *buf)
3882
3889
"%u" , (v >> 16 ) & 0x7fff );
3883
3890
return 0 ;
3884
3891
}
3892
+
3893
+ /*
3894
+ * Based on https://stackoverflow.com/questions/43002803
3895
+ *
3896
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3897
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3898
+ * "ErrorControl"=dword:00000001
3899
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3900
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3901
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3902
+ * 65,00,00,00
3903
+ * "Start"=dword:00000002
3904
+ * "Type"=dword:00000010
3905
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3906
+ * "ObjectName"="LocalSystem"
3907
+ * "ServiceSidType"=dword:00000001
3908
+ */
3909
+ int is_inside_windows_container (void )
3910
+ {
3911
+ static int inside_container = -1 ; /* -1 uninitialized */
3912
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
3913
+ HKEY handle = NULL ;
3914
+
3915
+ if (inside_container != -1 )
3916
+ return inside_container ;
3917
+
3918
+ inside_container = ERROR_SUCCESS ==
3919
+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
3920
+ RegCloseKey (handle );
3921
+
3922
+ return inside_container ;
3923
+ }
3924
+
3925
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
3926
+ {
3927
+ int fMode = S_IREAD ;
3928
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
3929
+ tag == IO_REPARSE_TAG_SYMLINK ) {
3930
+ int flag = S_IFLNK ;
3931
+ char buf [MAX_LONG_PATH ];
3932
+
3933
+ /*
3934
+ * Windows containers' mapped volumes are marked as reparse
3935
+ * points and look like symbolic links, but they are not.
3936
+ */
3937
+ if (path && is_inside_windows_container () &&
3938
+ readlink (path , buf , sizeof (buf )) > 27 &&
3939
+ starts_with (buf , "/ContainerMappedDirectories/" ))
3940
+ flag = S_IFDIR ;
3941
+
3942
+ fMode |= flag ;
3943
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
3944
+ fMode |= S_IFDIR ;
3945
+ else
3946
+ fMode |= S_IFREG ;
3947
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
3948
+ fMode |= S_IWRITE ;
3949
+ return fMode ;
3950
+ }
0 commit comments