@@ -959,7 +959,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
959
959
buf -> st_uid = 0 ;
960
960
buf -> st_nlink = 1 ;
961
961
buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
962
- reparse_tag );
962
+ reparse_tag , file_name );
963
963
buf -> st_size = S_ISLNK (buf -> st_mode ) ? link_len :
964
964
fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
965
965
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -1010,7 +1010,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
1010
1010
buf -> st_gid = 0 ;
1011
1011
buf -> st_uid = 0 ;
1012
1012
buf -> st_nlink = 1 ;
1013
- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
1013
+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
1014
1014
buf -> st_size = fdata .nFileSizeLow |
1015
1015
(((off_t )fdata .nFileSizeHigh )<<32 );
1016
1016
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -2464,6 +2464,13 @@ int mingw_rename(const char *pold, const char *pnew)
2464
2464
return 0 ;
2465
2465
gle = GetLastError ();
2466
2466
2467
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2468
+ /* Fall back to copy to destination & remove source */
2469
+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2470
+ return 0 ;
2471
+ gle = GetLastError ();
2472
+ }
2473
+
2467
2474
/* revert file attributes on failure */
2468
2475
if (attrs != INVALID_FILE_ATTRIBUTES )
2469
2476
SetFileAttributesW (wpnew , attrs );
@@ -3645,3 +3652,62 @@ int uname(struct utsname *buf)
3645
3652
"%u" , (v >> 16 ) & 0x7fff );
3646
3653
return 0 ;
3647
3654
}
3655
+
3656
+ /*
3657
+ * Based on https://stackoverflow.com/questions/43002803
3658
+ *
3659
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3660
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3661
+ * "ErrorControl"=dword:00000001
3662
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3663
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3664
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3665
+ * 65,00,00,00
3666
+ * "Start"=dword:00000002
3667
+ * "Type"=dword:00000010
3668
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3669
+ * "ObjectName"="LocalSystem"
3670
+ * "ServiceSidType"=dword:00000001
3671
+ */
3672
+ int is_inside_windows_container (void )
3673
+ {
3674
+ static int inside_container = -1 ; /* -1 uninitialized */
3675
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
3676
+ HKEY handle = NULL ;
3677
+
3678
+ if (inside_container != -1 )
3679
+ return inside_container ;
3680
+
3681
+ inside_container = ERROR_SUCCESS ==
3682
+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
3683
+ RegCloseKey (handle );
3684
+
3685
+ return inside_container ;
3686
+ }
3687
+
3688
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
3689
+ {
3690
+ int fMode = S_IREAD ;
3691
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
3692
+ tag == IO_REPARSE_TAG_SYMLINK ) {
3693
+ int flag = S_IFLNK ;
3694
+ char buf [MAX_LONG_PATH ];
3695
+
3696
+ /*
3697
+ * Windows containers' mapped volumes are marked as reparse
3698
+ * points and look like symbolic links, but they are not.
3699
+ */
3700
+ if (path && is_inside_windows_container () &&
3701
+ readlink (path , buf , sizeof (buf )) > 27 &&
3702
+ starts_with (buf , "/ContainerMappedDirectories/" ))
3703
+ flag = S_IFDIR ;
3704
+
3705
+ fMode |= flag ;
3706
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
3707
+ fMode |= S_IFDIR ;
3708
+ else
3709
+ fMode |= S_IFREG ;
3710
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
3711
+ fMode |= S_IWRITE ;
3712
+ return fMode ;
3713
+ }
0 commit comments