@@ -1122,7 +1122,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
11221122 buf -> st_uid = 0 ;
11231123 buf -> st_nlink = 1 ;
11241124 buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes ,
1125- reparse_tag );
1125+ reparse_tag , file_name );
11261126 buf -> st_size = S_ISLNK (buf -> st_mode ) ? link_len :
11271127 fdata .nFileSizeLow | (((off_t ) fdata .nFileSizeHigh ) << 32 );
11281128 buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -1173,7 +1173,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
11731173 buf -> st_gid = 0 ;
11741174 buf -> st_uid = 0 ;
11751175 buf -> st_nlink = 1 ;
1176- buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 );
1176+ buf -> st_mode = file_attr_to_st_mode (fdata .dwFileAttributes , 0 , NULL );
11771177 buf -> st_size = fdata .nFileSizeLow |
11781178 (((off_t )fdata .nFileSizeHigh )<<32 );
11791179 buf -> st_dev = buf -> st_rdev = 0 ; /* not used by Git */
@@ -2815,6 +2815,13 @@ int mingw_rename(const char *pold, const char *pnew)
28152815 gle = GetLastError ();
28162816 }
28172817
2818+ if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container ()) {
2819+ /* Fall back to copy to destination & remove source */
2820+ if (CopyFileW (wpold , wpnew , FALSE) && !mingw_unlink (pold ))
2821+ return 0 ;
2822+ gle = GetLastError ();
2823+ }
2824+
28182825 /* revert file attributes on failure */
28192826 if (attrs != INVALID_FILE_ATTRIBUTES )
28202827 SetFileAttributesW (wpnew , attrs );
@@ -4222,3 +4229,62 @@ int mingw_have_unix_sockets(void)
42224229 return ret ;
42234230}
42244231#endif
4232+
4233+ /*
4234+ * Based on https://stackoverflow.com/questions/43002803
4235+ *
4236+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
4237+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
4238+ * "ErrorControl"=dword:00000001
4239+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
4240+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
4241+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
4242+ * 65,00,00,00
4243+ * "Start"=dword:00000002
4244+ * "Type"=dword:00000010
4245+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
4246+ * "ObjectName"="LocalSystem"
4247+ * "ServiceSidType"=dword:00000001
4248+ */
4249+ int is_inside_windows_container (void )
4250+ {
4251+ static int inside_container = -1 ; /* -1 uninitialized */
4252+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
4253+ HKEY handle = NULL ;
4254+
4255+ if (inside_container != -1 )
4256+ return inside_container ;
4257+
4258+ inside_container = ERROR_SUCCESS ==
4259+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
4260+ RegCloseKey (handle );
4261+
4262+ return inside_container ;
4263+ }
4264+
4265+ int file_attr_to_st_mode (DWORD attr , DWORD tag , const char * path )
4266+ {
4267+ int fMode = S_IREAD ;
4268+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT ) &&
4269+ tag == IO_REPARSE_TAG_SYMLINK ) {
4270+ int flag = S_IFLNK ;
4271+ char buf [MAX_LONG_PATH ];
4272+
4273+ /*
4274+ * Windows containers' mapped volumes are marked as reparse
4275+ * points and look like symbolic links, but they are not.
4276+ */
4277+ if (path && is_inside_windows_container () &&
4278+ readlink (path , buf , sizeof (buf )) > 27 &&
4279+ starts_with (buf , "/ContainerMappedDirectories/" ))
4280+ flag = S_IFDIR ;
4281+
4282+ fMode |= flag ;
4283+ } else if (attr & FILE_ATTRIBUTE_DIRECTORY )
4284+ fMode |= S_IFDIR ;
4285+ else
4286+ fMode |= S_IFREG ;
4287+ if (!(attr & FILE_ATTRIBUTE_READONLY ))
4288+ fMode |= S_IWRITE ;
4289+ return fMode ;
4290+ }
0 commit comments