@@ -895,7 +895,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
895
895
buf -> st_uid = 0 ;
896
896
buf -> st_nlink = 1 ;
897
897
buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
898
- findbuf .dwReserved0 );
898
+ findbuf .dwReserved0 , file_name );
899
899
buf -> st_size = S_ISLNK (buf -> st_mode ) ? MAX_LONG_PATH :
900
900
fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
901
901
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -946,7 +946,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
946
946
buf -> st_gid = 0 ;
947
947
buf -> st_uid = 0 ;
948
948
buf -> st_nlink = 1 ;
949
- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
949
+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
950
950
buf -> st_size = fdata .nFileSizeLow |
951
951
(((off_t )fdata .nFileSizeHigh )<<32 );
952
952
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -2044,6 +2044,13 @@ int mingw_rename(const char *pold, const char *pnew)
2044
2044
return 0 ;
2045
2045
gle = GetLastError ();
2046
2046
2047
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2048
+ /* Fall back to copy to destination & remove source */
2049
+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2050
+ return 0 ;
2051
+ gle = GetLastError ();
2052
+ }
2053
+
2047
2054
/* revert file attributes on failure */
2048
2055
if (attrs != INVALID_FILE_ATTRIBUTES )
2049
2056
SetFileAttributesW (wpnew , attrs );
@@ -2981,3 +2988,62 @@ const char *program_data_config(void)
2981
2988
}
2982
2989
return * path .buf ? path .buf : NULL ;
2983
2990
}
2991
+
2992
+ /*
2993
+ * Based on https://stackoverflow.com/questions/43002803
2994
+ *
2995
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
2996
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
2997
+ * "ErrorControl"=dword:00000001
2998
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
2999
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3000
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3001
+ * 65,00,00,00
3002
+ * "Start"=dword:00000002
3003
+ * "Type"=dword:00000010
3004
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3005
+ * "ObjectName"="LocalSystem"
3006
+ * "ServiceSidType"=dword:00000001
3007
+ */
3008
+ int is_inside_windows_container (void )
3009
+ {
3010
+ static int inside_container = -1 ; /* -1 uninitialized */
3011
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
3012
+ HKEY handle = NULL ;
3013
+
3014
+ if (inside_container != -1 )
3015
+ return inside_container ;
3016
+
3017
+ inside_container = ERROR_SUCCESS ==
3018
+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
3019
+ RegCloseKey (handle );
3020
+
3021
+ return inside_container ;
3022
+ }
3023
+
3024
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
3025
+ {
3026
+ int fMode = S_IREAD ;
3027
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
3028
+ tag == IO_REPARSE_TAG_SYMLINK ) {
3029
+ int flag = S_IFLNK ;
3030
+ char buf [MAX_LONG_PATH ];
3031
+
3032
+ /*
3033
+ * Windows containers' mapped volumes are marked as reparse
3034
+ * points and look like symbolic links, but they are not.
3035
+ */
3036
+ if (path && is_inside_windows_container () &&
3037
+ readlink (path , buf , sizeof (buf )) > 27 &&
3038
+ starts_with (buf , "/ContainerMappedDirectories/" ))
3039
+ flag = S_IFDIR ;
3040
+
3041
+ fMode |= flag ;
3042
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
3043
+ fMode |= S_IFDIR ;
3044
+ else
3045
+ fMode |= S_IFREG ;
3046
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
3047
+ fMode |= S_IWRITE ;
3048
+ return fMode ;
3049
+ }
0 commit comments