@@ -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 );
@@ -3908,3 +3915,62 @@ int uname(struct utsname *buf)
3908
3915
"%u" , (v >> 16 ) & 0x7fff );
3909
3916
return 0 ;
3910
3917
}
3918
+
3919
+ /*
3920
+ * Based on https://stackoverflow.com/questions/43002803
3921
+ *
3922
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3923
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3924
+ * "ErrorControl"=dword:00000001
3925
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3926
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3927
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3928
+ * 65,00,00,00
3929
+ * "Start"=dword:00000002
3930
+ * "Type"=dword:00000010
3931
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3932
+ * "ObjectName"="LocalSystem"
3933
+ * "ServiceSidType"=dword:00000001
3934
+ */
3935
+ int is_inside_windows_container (void )
3936
+ {
3937
+ static int inside_container = -1 ; /* -1 uninitialized */
3938
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
3939
+ HKEY handle = NULL ;
3940
+
3941
+ if (inside_container != -1 )
3942
+ return inside_container ;
3943
+
3944
+ inside_container = ERROR_SUCCESS ==
3945
+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
3946
+ RegCloseKey (handle );
3947
+
3948
+ return inside_container ;
3949
+ }
3950
+
3951
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
3952
+ {
3953
+ int fMode = S_IREAD ;
3954
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
3955
+ tag == IO_REPARSE_TAG_SYMLINK ) {
3956
+ int flag = S_IFLNK ;
3957
+ char buf [MAX_LONG_PATH ];
3958
+
3959
+ /*
3960
+ * Windows containers' mapped volumes are marked as reparse
3961
+ * points and look like symbolic links, but they are not.
3962
+ */
3963
+ if (path && is_inside_windows_container () &&
3964
+ readlink (path , buf , sizeof (buf )) > 27 &&
3965
+ starts_with (buf , "/ContainerMappedDirectories/" ))
3966
+ flag = S_IFDIR ;
3967
+
3968
+ fMode |= flag ;
3969
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
3970
+ fMode |= S_IFDIR ;
3971
+ else
3972
+ fMode |= S_IFREG ;
3973
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
3974
+ fMode |= S_IWRITE ;
3975
+ return fMode ;
3976
+ }
0 commit comments