@@ -818,7 +818,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
818
818
buf -> st_uid = 0 ;
819
819
buf -> st_nlink = 1 ;
820
820
buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
821
- findbuf .dwReserved0 );
821
+ findbuf .dwReserved0 , file_name );
822
822
buf -> st_size = S_ISLNK (buf -> st_mode ) ? MAX_LONG_PATH :
823
823
fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
824
824
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -867,7 +867,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
867
867
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
868
868
buf -> st_gid = buf -> st_uid = 0 ;
869
869
buf -> st_nlink = 1 ;
870
- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
870
+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
871
871
buf -> st_size = fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
872
872
filetime_to_timespec (& (fdata .ftLastAccessTime ), & (buf -> st_atim ));
873
873
filetime_to_timespec (& (fdata .ftLastWriteTime ), & (buf -> st_mtim ));
@@ -2479,6 +2479,13 @@ int mingw_rename(const char *pold, const char *pnew)
2479
2479
return 0 ;
2480
2480
gle = GetLastError ();
2481
2481
2482
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2483
+ /* Fall back to copy to destination & remove source */
2484
+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2485
+ return 0 ;
2486
+ gle = GetLastError ();
2487
+ }
2488
+
2482
2489
/* revert file attributes on failure */
2483
2490
if (attrs != INVALID_FILE_ATTRIBUTES )
2484
2491
SetFileAttributesW (wpnew , attrs );
@@ -3556,3 +3563,62 @@ const char *program_data_config(void)
3556
3563
}
3557
3564
return * path .buf ? path .buf : NULL ;
3558
3565
}
3566
+
3567
+ /*
3568
+ * Based on https://stackoverflow.com/questions/43002803
3569
+ *
3570
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3571
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3572
+ * "ErrorControl"=dword:00000001
3573
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3574
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3575
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3576
+ * 65,00,00,00
3577
+ * "Start"=dword:00000002
3578
+ * "Type"=dword:00000010
3579
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3580
+ * "ObjectName"="LocalSystem"
3581
+ * "ServiceSidType"=dword:00000001
3582
+ */
3583
+ int is_inside_windows_container (void )
3584
+ {
3585
+ static int inside_container = -1 ; /* -1 uninitialized */
3586
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
3587
+ HKEY handle = NULL ;
3588
+
3589
+ if (inside_container != -1 )
3590
+ return inside_container ;
3591
+
3592
+ inside_container = ERROR_SUCCESS ==
3593
+ RegOpenKeyEx (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
3594
+ RegCloseKey (handle );
3595
+
3596
+ return inside_container ;
3597
+ }
3598
+
3599
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
3600
+ {
3601
+ int fMode = S_IREAD ;
3602
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
3603
+ tag == IO_REPARSE_TAG_SYMLINK ) {
3604
+ int flag = S_IFLNK ;
3605
+ char buf [MAX_LONG_PATH ];
3606
+
3607
+ /*
3608
+ * Windows containers' mapped volumes are marked as reparse
3609
+ * points and look like symbolic links, but they are not.
3610
+ */
3611
+ if (path && is_inside_windows_container () &&
3612
+ readlink (path , buf , sizeof (buf )) > 27 &&
3613
+ starts_with (buf , "/ContainerMappedDirectories/" ))
3614
+ flag = S_IFDIR ;
3615
+
3616
+ fMode |= flag ;
3617
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
3618
+ fMode |= S_IFDIR ;
3619
+ else
3620
+ fMode |= S_IFREG ;
3621
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
3622
+ fMode |= S_IWRITE ;
3623
+ return fMode ;
3624
+ }
0 commit comments