@@ -1121,7 +1121,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
1121
1121
buf -> st_uid = 0 ;
1122
1122
buf -> st_nlink = 1 ;
1123
1123
buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
1124
- reparse_tag );
1124
+ reparse_tag , file_name );
1125
1125
buf -> st_size = S_ISLNK (buf -> st_mode ) ? link_len :
1126
1126
fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
1127
1127
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -1172,7 +1172,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
1172
1172
buf -> st_gid = 0 ;
1173
1173
buf -> st_uid = 0 ;
1174
1174
buf -> st_nlink = 1 ;
1175
- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
1175
+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
1176
1176
buf -> st_size = fdata .nFileSizeLow |
1177
1177
(((off_t )fdata .nFileSizeHigh )<<32 );
1178
1178
buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -2738,6 +2738,13 @@ int mingw_rename(const char *pold, const char *pnew)
2738
2738
gle = GetLastError ();
2739
2739
}
2740
2740
2741
+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2742
+ /* Fall back to copy to destination & remove source */
2743
+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2744
+ return 0 ;
2745
+ gle = GetLastError ();
2746
+ }
2747
+
2741
2748
/* revert file attributes on failure */
2742
2749
if (attrs != INVALID_FILE_ATTRIBUTES )
2743
2750
SetFileAttributesW (wpnew , attrs );
@@ -4145,3 +4152,62 @@ int mingw_have_unix_sockets(void)
4145
4152
return ret ;
4146
4153
}
4147
4154
#endif
4155
+
4156
+ /*
4157
+ * Based on https://stackoverflow.com/questions/43002803
4158
+ *
4159
+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
4160
+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
4161
+ * "ErrorControl"=dword:00000001
4162
+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
4163
+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
4164
+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
4165
+ * 65,00,00,00
4166
+ * "Start"=dword:00000002
4167
+ * "Type"=dword:00000010
4168
+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
4169
+ * "ObjectName"="LocalSystem"
4170
+ * "ServiceSidType"=dword:00000001
4171
+ */
4172
+ int is_inside_windows_container (void )
4173
+ {
4174
+ static int inside_container = -1 ; /* -1 uninitialized */
4175
+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
4176
+ HKEY handle = NULL ;
4177
+
4178
+ if (inside_container != -1 )
4179
+ return inside_container ;
4180
+
4181
+ inside_container = ERROR_SUCCESS ==
4182
+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
4183
+ RegCloseKey (handle );
4184
+
4185
+ return inside_container ;
4186
+ }
4187
+
4188
+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
4189
+ {
4190
+ int fMode = S_IREAD ;
4191
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
4192
+ tag == IO_REPARSE_TAG_SYMLINK ) {
4193
+ int flag = S_IFLNK ;
4194
+ char buf [MAX_LONG_PATH ];
4195
+
4196
+ /*
4197
+ * Windows containers' mapped volumes are marked as reparse
4198
+ * points and look like symbolic links, but they are not.
4199
+ */
4200
+ if (path && is_inside_windows_container () &&
4201
+ readlink (path , buf , sizeof (buf )) > 27 &&
4202
+ starts_with (buf , "/ContainerMappedDirectories/" ))
4203
+ flag = S_IFDIR ;
4204
+
4205
+ fMode |= flag ;
4206
+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
4207
+ fMode |= S_IFDIR ;
4208
+ else
4209
+ fMode |= S_IFREG ;
4210
+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
4211
+ fMode |= S_IWRITE ;
4212
+ return fMode ;
4213
+ }
0 commit comments