@@ -945,7 +945,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
945
945
buf -> st_uid = 0 ;
946
946
buf -> st_nlink = 1 ;
947
947
buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
948
- findbuf .dwReserved0 );
948
+ findbuf .dwReserved0 , file_name );
949
949
buf -> st_size = S_ISLNK (buf -> st_mode ) ? MAX_LONG_PATH :
950
950
fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
951
951
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -996,7 +996,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
996
996
buf -> st_gid = 0 ;
997
997
buf -> st_uid = 0 ;
998
998
buf -> st_nlink = 1 ;
999
- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
999
+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
1000
1000
buf -> st_size = fdata .nFileSizeLow |
1001
1001
(((off_t )fdata .nFileSizeHigh )<<32 );
1002
1002
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -2417,6 +2417,13 @@ int mingw_rename(const char *pold, const char *pnew)
2417
2417
return 0 ;
2418
2418
gle = GetLastError ();
2419
2419
2420
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2421
+ /* Fall back to copy to destination & remove source */
2422
+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2423
+ return 0 ;
2424
+ gle = GetLastError ();
2425
+ }
2426
+
2420
2427
/* revert file attributes on failure */
2421
2428
if (attrs != INVALID_FILE_ATTRIBUTES )
2422
2429
SetFileAttributesW (wpnew , attrs );
@@ -3567,3 +3574,62 @@ int uname(struct utsname *buf)
3567
3574
"%u" , (v >> 16 ) & 0x7fff );
3568
3575
return 0 ;
3569
3576
}
3577
+
3578
+ /*
3579
+ * Based on https://stackoverflow.com/questions/43002803
3580
+ *
3581
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3582
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3583
+ * "ErrorControl"=dword:00000001
3584
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3585
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3586
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3587
+ * 65,00,00,00
3588
+ * "Start"=dword:00000002
3589
+ * "Type"=dword:00000010
3590
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3591
+ * "ObjectName"="LocalSystem"
3592
+ * "ServiceSidType"=dword:00000001
3593
+ */
3594
+ int is_inside_windows_container (void )
3595
+ {
3596
+ static int inside_container = -1 ; /* -1 uninitialized */
3597
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
3598
+ HKEY handle = NULL ;
3599
+
3600
+ if (inside_container != -1 )
3601
+ return inside_container ;
3602
+
3603
+ inside_container = ERROR_SUCCESS ==
3604
+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
3605
+ RegCloseKey (handle );
3606
+
3607
+ return inside_container ;
3608
+ }
3609
+
3610
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
3611
+ {
3612
+ int fMode = S_IREAD ;
3613
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
3614
+ tag == IO_REPARSE_TAG_SYMLINK ) {
3615
+ int flag = S_IFLNK ;
3616
+ char buf [MAX_LONG_PATH ];
3617
+
3618
+ /*
3619
+ * Windows containers' mapped volumes are marked as reparse
3620
+ * points and look like symbolic links, but they are not.
3621
+ */
3622
+ if (path && is_inside_windows_container () &&
3623
+ readlink (path , buf , sizeof (buf )) > 27 &&
3624
+ starts_with (buf , "/ContainerMappedDirectories/" ))
3625
+ flag = S_IFDIR ;
3626
+
3627
+ fMode |= flag ;
3628
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
3629
+ fMode |= S_IFDIR ;
3630
+ else
3631
+ fMode |= S_IFREG ;
3632
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
3633
+ fMode |= S_IWRITE ;
3634
+ return fMode ;
3635
+ }
0 commit comments