@@ -1039,7 +1039,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
1039
1039
buf -> st_uid = 0 ;
1040
1040
buf -> st_nlink = 1 ;
1041
1041
buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
1042
- reparse_tag );
1042
+ reparse_tag , file_name );
1043
1043
buf -> st_size = S_ISLNK (buf -> st_mode ) ? link_len :
1044
1044
fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
1045
1045
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -1090,7 +1090,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
1090
1090
buf -> st_gid = 0 ;
1091
1091
buf -> st_uid = 0 ;
1092
1092
buf -> st_nlink = 1 ;
1093
- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
1093
+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
1094
1094
buf -> st_size = fdata .nFileSizeLow |
1095
1095
(((off_t )fdata .nFileSizeHigh )<<32 );
1096
1096
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -2576,6 +2576,13 @@ int mingw_rename(const char *pold, const char *pnew)
2576
2576
return 0 ;
2577
2577
gle = GetLastError ();
2578
2578
2579
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2580
+ /* Fall back to copy to destination & remove source */
2581
+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2582
+ return 0 ;
2583
+ gle = GetLastError ();
2584
+ }
2585
+
2579
2586
/* revert file attributes on failure */
2580
2587
if (attrs != INVALID_FILE_ATTRIBUTES )
2581
2588
SetFileAttributesW (wpnew , attrs );
@@ -3913,3 +3920,62 @@ int uname(struct utsname *buf)
3913
3920
"%u" , (v >> 16 ) & 0x7fff );
3914
3921
return 0 ;
3915
3922
}
3923
+
3924
+ /*
3925
+ * Based on https://stackoverflow.com/questions/43002803
3926
+ *
3927
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3928
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3929
+ * "ErrorControl"=dword:00000001
3930
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3931
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3932
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3933
+ * 65,00,00,00
3934
+ * "Start"=dword:00000002
3935
+ * "Type"=dword:00000010
3936
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3937
+ * "ObjectName"="LocalSystem"
3938
+ * "ServiceSidType"=dword:00000001
3939
+ */
3940
+ int is_inside_windows_container (void )
3941
+ {
3942
+ static int inside_container = -1 ; /* -1 uninitialized */
3943
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
3944
+ HKEY handle = NULL ;
3945
+
3946
+ if (inside_container != -1 )
3947
+ return inside_container ;
3948
+
3949
+ inside_container = ERROR_SUCCESS ==
3950
+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
3951
+ RegCloseKey (handle );
3952
+
3953
+ return inside_container ;
3954
+ }
3955
+
3956
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
3957
+ {
3958
+ int fMode = S_IREAD ;
3959
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
3960
+ tag == IO_REPARSE_TAG_SYMLINK ) {
3961
+ int flag = S_IFLNK ;
3962
+ char buf [MAX_LONG_PATH ];
3963
+
3964
+ /*
3965
+ * Windows containers' mapped volumes are marked as reparse
3966
+ * points and look like symbolic links, but they are not.
3967
+ */
3968
+ if (path && is_inside_windows_container () &&
3969
+ readlink (path , buf , sizeof (buf )) > 27 &&
3970
+ starts_with (buf , "/ContainerMappedDirectories/" ))
3971
+ flag = S_IFDIR ;
3972
+
3973
+ fMode |= flag ;
3974
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
3975
+ fMode |= S_IFDIR ;
3976
+ else
3977
+ fMode |= S_IFREG ;
3978
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
3979
+ fMode |= S_IWRITE ;
3980
+ return fMode ;
3981
+ }
0 commit comments