@@ -244,7 +244,6 @@ enum hide_dotfiles_type {
244
244
HIDE_DOTFILES_DOTGITONLY
245
245
};
246
246
247
- static int core_restrict_inherited_handles = -1 ;
248
247
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY ;
249
248
static char * unset_environment_variables ;
250
249
@@ -268,15 +267,6 @@ int mingw_core_config(const char *var, const char *value,
268
267
return 0 ;
269
268
}
270
269
271
- if (!strcmp (var , "core.restrictinheritedhandles" )) {
272
- if (value && !strcasecmp (value , "auto" ))
273
- core_restrict_inherited_handles = -1 ;
274
- else
275
- core_restrict_inherited_handles =
276
- git_config_bool (var , value );
277
- return 0 ;
278
- }
279
-
280
270
return 0 ;
281
271
}
282
272
@@ -588,13 +578,24 @@ static int mingw_open_existing(const wchar_t *filename, int oflags, ...)
588
578
& security_attributes , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL );
589
579
if (handle == INVALID_HANDLE_VALUE ) {
590
580
DWORD err = GetLastError ();
581
+ if (err == ERROR_ACCESS_DENIED ) {
582
+ DWORD attrs = GetFileAttributesW (filename );
583
+ if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY ))
584
+ handle = CreateFileW (filename , access ,
585
+ FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE ,
586
+ & security_attributes , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS , NULL );
587
+ }
591
588
592
- /* See `mingw_open_append()` for why we have this conversion. */
593
- if (err == ERROR_INVALID_PARAMETER )
594
- err = ERROR_PATH_NOT_FOUND ;
589
+ if (handle == INVALID_HANDLE_VALUE ) {
590
+ err = GetLastError ();
595
591
596
- errno = err_win_to_posix (err );
597
- return -1 ;
592
+ /* See `mingw_open_append()` for why we have this conversion. */
593
+ if (err == ERROR_INVALID_PARAMETER )
594
+ err = ERROR_PATH_NOT_FOUND ;
595
+
596
+ errno = err_win_to_posix (err );
597
+ return -1 ;
598
+ }
598
599
}
599
600
600
601
fd = _open_osfhandle ((intptr_t )handle , oflags | O_BINARY );
@@ -1656,7 +1657,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
1656
1657
const char * dir ,
1657
1658
int prepend_cmd , int fhin , int fhout , int fherr )
1658
1659
{
1659
- static int restrict_handle_inheritance = -1 ;
1660
1660
STARTUPINFOEXW si ;
1661
1661
PROCESS_INFORMATION pi ;
1662
1662
LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL ;
@@ -1676,16 +1676,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
1676
1676
/* Make sure to override previous errors, if any */
1677
1677
errno = 0 ;
1678
1678
1679
- if (restrict_handle_inheritance < 0 )
1680
- restrict_handle_inheritance = core_restrict_inherited_handles ;
1681
- /*
1682
- * The following code to restrict which handles are inherited seems
1683
- * to work properly only on Windows 7 and later, so let's disable it
1684
- * on Windows Vista and 2008.
1685
- */
1686
- if (restrict_handle_inheritance < 0 )
1687
- restrict_handle_inheritance = GetVersion () >> 16 >= 7601 ;
1688
-
1689
1679
do_unset_environment_variables ();
1690
1680
1691
1681
/* Determine whether or not we are associated to a console */
@@ -1787,7 +1777,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
1787
1777
wenvblk = make_environment_block (deltaenv );
1788
1778
1789
1779
memset (& pi , 0 , sizeof (pi ));
1790
- if (restrict_handle_inheritance && stdhandles_count &&
1780
+ if (stdhandles_count &&
1791
1781
(InitializeProcThreadAttributeList (NULL , 1 , 0 , & size ) ||
1792
1782
GetLastError () == ERROR_INSUFFICIENT_BUFFER ) &&
1793
1783
(attr_list = (LPPROC_THREAD_ATTRIBUTE_LIST )
@@ -1808,52 +1798,13 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
1808
1798
& si .StartupInfo , & pi );
1809
1799
1810
1800
/*
1811
- * On Windows 2008 R2, it seems that specifying certain types of handles
1812
- * (such as FILE_TYPE_CHAR or FILE_TYPE_PIPE) will always produce an
1813
- * error. Rather than playing finicky and fragile games, let's just try
1814
- * to detect this situation and simply try again without restricting any
1815
- * handle inheritance. This is still better than failing to create
1816
- * processes.
1801
+ * On the off-chance that something with the file handle restriction
1802
+ * went wrong, silently fall back to trying without it.
1817
1803
*/
1818
- if (!ret && restrict_handle_inheritance && stdhandles_count ) {
1804
+ if (!ret && stdhandles_count ) {
1819
1805
DWORD err = GetLastError ();
1820
1806
struct strbuf buf = STRBUF_INIT ;
1821
1807
1822
- if (err != ERROR_NO_SYSTEM_RESOURCES &&
1823
- /*
1824
- * On Windows 7 and earlier, handles on pipes and character
1825
- * devices are inherited automatically, and cannot be
1826
- * specified in the thread handle list. Rather than trying
1827
- * to catch each and every corner case (and running the
1828
- * chance of *still* forgetting a few), let's just fall
1829
- * back to creating the process without trying to limit the
1830
- * handle inheritance.
1831
- */
1832
- !(err == ERROR_INVALID_PARAMETER &&
1833
- GetVersion () >> 16 < 9200 ) &&
1834
- !getenv ("SUPPRESS_HANDLE_INHERITANCE_WARNING" )) {
1835
- DWORD fl = 0 ;
1836
- int i ;
1837
-
1838
- setenv ("SUPPRESS_HANDLE_INHERITANCE_WARNING" , "1" , 1 );
1839
-
1840
- for (i = 0 ; i < stdhandles_count ; i ++ ) {
1841
- HANDLE h = stdhandles [i ];
1842
- strbuf_addf (& buf , "handle #%d: %p (type %lx, "
1843
- "handle info (%d) %lx\n" , i , h ,
1844
- GetFileType (h ),
1845
- GetHandleInformation (h , & fl ),
1846
- fl );
1847
- }
1848
- strbuf_addstr (& buf , "\nThis is a bug; please report it "
1849
- "at\nhttps://github.com/git-for-windows/"
1850
- "git/issues/new\n\n"
1851
- "To suppress this warning, please set "
1852
- "the environment variable\n\n"
1853
- "\tSUPPRESS_HANDLE_INHERITANCE_WARNING=1"
1854
- "\n" );
1855
- }
1856
- restrict_handle_inheritance = 0 ;
1857
1808
flags &= ~EXTENDED_STARTUPINFO_PRESENT ;
1858
1809
ret = CreateProcessW (* wcmd ? wcmd : NULL , wargs , NULL , NULL ,
1859
1810
TRUE, flags , wenvblk , dir ? wdir : NULL ,
@@ -2326,7 +2277,9 @@ int mingw_rename(const char *pold, const char *pnew)
2326
2277
* current system doesn't support FileRenameInfoEx. Keep us
2327
2278
* from using it in future calls and retry.
2328
2279
*/
2329
- if (gle == ERROR_INVALID_PARAMETER ) {
2280
+ if (gle == ERROR_INVALID_PARAMETER ||
2281
+ gle == ERROR_NOT_SUPPORTED ||
2282
+ gle == ERROR_INVALID_FUNCTION ) {
2330
2283
supports_file_rename_info_ex = 0 ;
2331
2284
goto repeat ;
2332
2285
}
0 commit comments