@@ -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 */
@@ -2053,6 +2053,13 @@ int mingw_rename(const char *pold, const char *pnew)
2053
2053
return 0;
2054
2054
gle = GetLastError();
2055
2055
2056
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container()) {
2057
+ /* Fall back to copy to destination & remove source */
2058
+ if (CopyFileW(wpold, wpnew, FALSE) && !mingw_unlink(pold))
2059
+ return 0;
2060
+ gle = GetLastError();
2061
+ }
2062
+
2056
2063
/* revert file attributes on failure */
2057
2064
if (attrs != INVALID_FILE_ATTRIBUTES)
2058
2065
SetFileAttributesW(wpnew, attrs);
@@ -2992,3 +2999,62 @@ const char *program_data_config(void)
2992
2999
}
2993
3000
return *path.buf ? path.buf : NULL;
2994
3001
}
3002
+
3003
+ /*
3004
+ * Based on https://stackoverflow.com/questions/43002803
3005
+ *
3006
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3007
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3008
+ * "ErrorControl"=dword:00000001
3009
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3010
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3011
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3012
+ * 65,00,00,00
3013
+ * "Start"=dword:00000002
3014
+ * "Type"=dword:00000010
3015
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3016
+ * "ObjectName"="LocalSystem"
3017
+ * "ServiceSidType"=dword:00000001
3018
+ */
3019
+ int is_inside_windows_container(void)
3020
+ {
3021
+ static int inside_container = -1; /* -1 uninitialized */
3022
+ const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
3023
+ HKEY handle = NULL;
3024
+
3025
+ if (inside_container != -1)
3026
+ return inside_container;
3027
+
3028
+ inside_container = ERROR_SUCCESS ==
3029
+ RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
3030
+ RegCloseKey(handle);
3031
+
3032
+ return inside_container;
3033
+ }
3034
+
3035
+ int file_attr_to_st_mode (DWORD attr, DWORD tag, const char *path)
3036
+ {
3037
+ int fMode = S_IREAD;
3038
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT) &&
3039
+ tag == IO_REPARSE_TAG_SYMLINK) {
3040
+ int flag = S_IFLNK;
3041
+ char buf[MAX_LONG_PATH];
3042
+
3043
+ /*
3044
+ * Windows containers' mapped volumes are marked as reparse
3045
+ * points and look like symbolic links, but they are not.
3046
+ */
3047
+ if (path && is_inside_windows_container() &&
3048
+ readlink(path, buf, sizeof(buf)) > 27 &&
3049
+ starts_with(buf, "/ContainerMappedDirectories/"))
3050
+ flag = S_IFDIR;
3051
+
3052
+ fMode |= flag;
3053
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY)
3054
+ fMode |= S_IFDIR;
3055
+ else
3056
+ fMode |= S_IFREG;
3057
+ if (!(attr & FILE_ATTRIBUTE_READONLY))
3058
+ fMode |= S_IWRITE;
3059
+ return fMode;
3060
+ }
0 commit comments