@@ -855,7 +855,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
855
855
buf -> st_uid = 0 ;
856
856
buf -> st_nlink = 1 ;
857
857
buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
858
- findbuf .dwReserved0 );
858
+ findbuf .dwReserved0 , file_name );
859
859
buf -> st_size = S_ISLNK (buf -> st_mode ) ? MAX_LONG_PATH :
860
860
fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
861
861
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -904,7 +904,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
904
904
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
905
905
buf -> st_gid = buf -> st_uid = 0 ;
906
906
buf -> st_nlink = 1 ;
907
- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
907
+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
908
908
buf -> st_size = fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
909
909
filetime_to_timespec (& (fdata .ftLastAccessTime ), & (buf -> st_atim ));
910
910
filetime_to_timespec (& (fdata .ftLastWriteTime ), & (buf -> st_mtim ));
@@ -2516,6 +2516,13 @@ int mingw_rename(const char *pold, const char *pnew)
2516
2516
return 0 ;
2517
2517
gle = GetLastError ();
2518
2518
2519
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2520
+ /* Fall back to copy to destination & remove source */
2521
+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2522
+ return 0 ;
2523
+ gle = GetLastError ();
2524
+ }
2525
+
2519
2526
/* revert file attributes on failure */
2520
2527
if (attrs != INVALID_FILE_ATTRIBUTES )
2521
2528
SetFileAttributesW (wpnew , attrs );
@@ -3593,3 +3600,62 @@ const char *program_data_config(void)
3593
3600
}
3594
3601
return * path .buf ? path .buf : NULL ;
3595
3602
}
3603
+
3604
+ /*
3605
+ * Based on https://stackoverflow.com/questions/43002803
3606
+ *
3607
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3608
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3609
+ * "ErrorControl"=dword:00000001
3610
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3611
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3612
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3613
+ * 65,00,00,00
3614
+ * "Start"=dword:00000002
3615
+ * "Type"=dword:00000010
3616
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3617
+ * "ObjectName"="LocalSystem"
3618
+ * "ServiceSidType"=dword:00000001
3619
+ */
3620
+ int is_inside_windows_container (void )
3621
+ {
3622
+ static int inside_container = -1 ; /* -1 uninitialized */
3623
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
3624
+ HKEY handle = NULL ;
3625
+
3626
+ if (inside_container != -1 )
3627
+ return inside_container ;
3628
+
3629
+ inside_container = ERROR_SUCCESS ==
3630
+ RegOpenKeyEx (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
3631
+ RegCloseKey (handle );
3632
+
3633
+ return inside_container ;
3634
+ }
3635
+
3636
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
3637
+ {
3638
+ int fMode = S_IREAD ;
3639
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
3640
+ tag == IO_REPARSE_TAG_SYMLINK ) {
3641
+ int flag = S_IFLNK ;
3642
+ char buf [MAX_LONG_PATH ];
3643
+
3644
+ /*
3645
+ * Windows containers' mapped volumes are marked as reparse
3646
+ * points and look like symbolic links, but they are not.
3647
+ */
3648
+ if (path && is_inside_windows_container () &&
3649
+ readlink (path , buf , sizeof (buf )) > 27 &&
3650
+ starts_with (buf , "/ContainerMappedDirectories/" ))
3651
+ flag = S_IFDIR ;
3652
+
3653
+ fMode |= flag ;
3654
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
3655
+ fMode |= S_IFDIR ;
3656
+ else
3657
+ fMode |= S_IFREG ;
3658
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
3659
+ fMode |= S_IWRITE ;
3660
+ return fMode ;
3661
+ }
0 commit comments