@@ -983,7 +983,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
983
983
buf -> st_uid = 0 ;
984
984
buf -> st_nlink = 1 ;
985
985
buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
986
- reparse_tag );
986
+ reparse_tag , file_name );
987
987
buf -> st_size = S_ISLNK (buf -> st_mode ) ? link_len :
988
988
fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
989
989
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -1034,7 +1034,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
1034
1034
buf -> st_gid = 0 ;
1035
1035
buf -> st_uid = 0 ;
1036
1036
buf -> st_nlink = 1 ;
1037
- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
1037
+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
1038
1038
buf -> st_size = fdata .nFileSizeLow |
1039
1039
(((off_t )fdata .nFileSizeHigh )<<32 );
1040
1040
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -2509,6 +2509,13 @@ int mingw_rename(const char *pold, const char *pnew)
2509
2509
return 0 ;
2510
2510
gle = GetLastError ();
2511
2511
2512
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2513
+ /* Fall back to copy to destination & remove source */
2514
+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2515
+ return 0 ;
2516
+ gle = GetLastError ();
2517
+ }
2518
+
2512
2519
/* revert file attributes on failure */
2513
2520
if (attrs != INVALID_FILE_ATTRIBUTES )
2514
2521
SetFileAttributesW (wpnew , attrs );
@@ -3776,3 +3783,62 @@ int uname(struct utsname *buf)
3776
3783
"%u" , (v >> 16 ) & 0x7fff );
3777
3784
return 0 ;
3778
3785
}
3786
+
3787
+ /*
3788
+ * Based on https://stackoverflow.com/questions/43002803
3789
+ *
3790
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3791
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3792
+ * "ErrorControl"=dword:00000001
3793
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3794
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3795
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3796
+ * 65,00,00,00
3797
+ * "Start"=dword:00000002
3798
+ * "Type"=dword:00000010
3799
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3800
+ * "ObjectName"="LocalSystem"
3801
+ * "ServiceSidType"=dword:00000001
3802
+ */
3803
+ int is_inside_windows_container (void )
3804
+ {
3805
+ static int inside_container = -1 ; /* -1 uninitialized */
3806
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
3807
+ HKEY handle = NULL ;
3808
+
3809
+ if (inside_container != -1 )
3810
+ return inside_container ;
3811
+
3812
+ inside_container = ERROR_SUCCESS ==
3813
+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
3814
+ RegCloseKey (handle );
3815
+
3816
+ return inside_container ;
3817
+ }
3818
+
3819
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
3820
+ {
3821
+ int fMode = S_IREAD ;
3822
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
3823
+ tag == IO_REPARSE_TAG_SYMLINK ) {
3824
+ int flag = S_IFLNK ;
3825
+ char buf [MAX_LONG_PATH ];
3826
+
3827
+ /*
3828
+ * Windows containers' mapped volumes are marked as reparse
3829
+ * points and look like symbolic links, but they are not.
3830
+ */
3831
+ if (path && is_inside_windows_container () &&
3832
+ readlink (path , buf , sizeof (buf )) > 27 &&
3833
+ starts_with (buf , "/ContainerMappedDirectories/" ))
3834
+ flag = S_IFDIR ;
3835
+
3836
+ fMode |= flag ;
3837
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
3838
+ fMode |= S_IFDIR ;
3839
+ else
3840
+ fMode |= S_IFREG ;
3841
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
3842
+ fMode |= S_IWRITE ;
3843
+ return fMode ;
3844
+ }
0 commit comments