@@ -775,7 +775,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
775
775
buf -> st_uid = 0 ;
776
776
buf -> st_nlink = 1 ;
777
777
buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
778
- findbuf .dwReserved0 );
778
+ findbuf .dwReserved0 , file_name );
779
779
buf -> st_size = S_ISLNK (buf -> st_mode ) ? MAX_LONG_PATH :
780
780
fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
781
781
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -824,7 +824,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
824
824
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
825
825
buf -> st_gid = buf -> st_uid = 0 ;
826
826
buf -> st_nlink = 1 ;
827
- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
827
+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
828
828
buf -> st_size = fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
829
829
filetime_to_timespec (& (fdata .ftLastAccessTime ), & (buf -> st_atim ));
830
830
filetime_to_timespec (& (fdata .ftLastWriteTime ), & (buf -> st_mtim ));
@@ -2436,6 +2436,13 @@ int mingw_rename(const char *pold, const char *pnew)
2436
2436
return 0 ;
2437
2437
gle = GetLastError ();
2438
2438
2439
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2440
+ /* Fall back to copy to destination & remove source */
2441
+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2442
+ return 0 ;
2443
+ gle = GetLastError ();
2444
+ }
2445
+
2439
2446
/* revert file attributes on failure */
2440
2447
if (attrs != INVALID_FILE_ATTRIBUTES )
2441
2448
SetFileAttributesW (wpnew , attrs );
@@ -3513,3 +3520,62 @@ const char *program_data_config(void)
3513
3520
}
3514
3521
return * path .buf ? path .buf : NULL ;
3515
3522
}
3523
+
3524
+ /*
3525
+ * Based on https://stackoverflow.com/questions/43002803
3526
+ *
3527
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3528
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3529
+ * "ErrorControl"=dword:00000001
3530
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3531
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3532
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3533
+ * 65,00,00,00
3534
+ * "Start"=dword:00000002
3535
+ * "Type"=dword:00000010
3536
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3537
+ * "ObjectName"="LocalSystem"
3538
+ * "ServiceSidType"=dword:00000001
3539
+ */
3540
+ int is_inside_windows_container (void )
3541
+ {
3542
+ static int inside_container = -1 ; /* -1 uninitialized */
3543
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
3544
+ HKEY handle = NULL ;
3545
+
3546
+ if (inside_container != -1 )
3547
+ return inside_container ;
3548
+
3549
+ inside_container = ERROR_SUCCESS ==
3550
+ RegOpenKeyEx (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
3551
+ RegCloseKey (handle );
3552
+
3553
+ return inside_container ;
3554
+ }
3555
+
3556
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
3557
+ {
3558
+ int fMode = S_IREAD ;
3559
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
3560
+ tag == IO_REPARSE_TAG_SYMLINK ) {
3561
+ int flag = S_IFLNK ;
3562
+ char buf [MAX_LONG_PATH ];
3563
+
3564
+ /*
3565
+ * Windows containers' mapped volumes are marked as reparse
3566
+ * points and look like symbolic links, but they are not.
3567
+ */
3568
+ if (path && is_inside_windows_container () &&
3569
+ !readlink (path , buf , sizeof (buf )) &&
3570
+ starts_with (buf , "/ContainerMappedDirectories/" ))
3571
+ flag = S_IFDIR ;
3572
+
3573
+ fMode |= flag ;
3574
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
3575
+ fMode |= S_IFDIR ;
3576
+ else
3577
+ fMode |= S_IFREG ;
3578
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
3579
+ fMode |= S_IWRITE ;
3580
+ return fMode ;
3581
+ }
0 commit comments