@@ -980,7 +980,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
980
980
buf -> st_uid = 0 ;
981
981
buf -> st_nlink = 1 ;
982
982
buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
983
- reparse_tag );
983
+ reparse_tag , file_name );
984
984
buf -> st_size = S_ISLNK (buf -> st_mode ) ? link_len :
985
985
fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
986
986
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -1031,7 +1031,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
1031
1031
buf -> st_gid = 0 ;
1032
1032
buf -> st_uid = 0 ;
1033
1033
buf -> st_nlink = 1 ;
1034
- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
1034
+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
1035
1035
buf -> st_size = fdata .nFileSizeLow |
1036
1036
(((off_t )fdata .nFileSizeHigh )<<32 );
1037
1037
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -2485,6 +2485,13 @@ int mingw_rename(const char *pold, const char *pnew)
2485
2485
return 0 ;
2486
2486
gle = GetLastError ();
2487
2487
2488
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2489
+ /* Fall back to copy to destination & remove source */
2490
+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2491
+ return 0 ;
2492
+ gle = GetLastError ();
2493
+ }
2494
+
2488
2495
/* revert file attributes on failure */
2489
2496
if (attrs != INVALID_FILE_ATTRIBUTES )
2490
2497
SetFileAttributesW (wpnew , attrs );
@@ -3666,3 +3673,62 @@ int uname(struct utsname *buf)
3666
3673
"%u" , (v >> 16 ) & 0x7fff );
3667
3674
return 0 ;
3668
3675
}
3676
+
3677
+ /*
3678
+ * Based on https://stackoverflow.com/questions/43002803
3679
+ *
3680
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3681
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3682
+ * "ErrorControl"=dword:00000001
3683
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3684
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3685
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3686
+ * 65,00,00,00
3687
+ * "Start"=dword:00000002
3688
+ * "Type"=dword:00000010
3689
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3690
+ * "ObjectName"="LocalSystem"
3691
+ * "ServiceSidType"=dword:00000001
3692
+ */
3693
+ int is_inside_windows_container (void )
3694
+ {
3695
+ static int inside_container = -1 ; /* -1 uninitialized */
3696
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
3697
+ HKEY handle = NULL ;
3698
+
3699
+ if (inside_container != -1 )
3700
+ return inside_container ;
3701
+
3702
+ inside_container = ERROR_SUCCESS ==
3703
+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
3704
+ RegCloseKey (handle );
3705
+
3706
+ return inside_container ;
3707
+ }
3708
+
3709
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
3710
+ {
3711
+ int fMode = S_IREAD ;
3712
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
3713
+ tag == IO_REPARSE_TAG_SYMLINK ) {
3714
+ int flag = S_IFLNK ;
3715
+ char buf [MAX_LONG_PATH ];
3716
+
3717
+ /*
3718
+ * Windows containers' mapped volumes are marked as reparse
3719
+ * points and look like symbolic links, but they are not.
3720
+ */
3721
+ if (path && is_inside_windows_container () &&
3722
+ readlink (path , buf , sizeof (buf )) > 27 &&
3723
+ starts_with (buf , "/ContainerMappedDirectories/" ))
3724
+ flag = S_IFDIR ;
3725
+
3726
+ fMode |= flag ;
3727
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
3728
+ fMode |= S_IFDIR ;
3729
+ else
3730
+ fMode |= S_IFREG ;
3731
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
3732
+ fMode |= S_IWRITE ;
3733
+ return fMode ;
3734
+ }
0 commit comments