diff --git a/LOG b/LOG index f361b3eb9b..ac6022ff0a 100644 --- a/LOG +++ b/LOG @@ -883,3 +883,5 @@ so the reduced version checks that p is a procedure. Also make the same change for #2%for-each. cp0.ss, 4.ms +- Mitigate a race condition in Windows when deleting files and directories. + windows.c diff --git a/c/windows.c b/c/windows.c index bf4da57253..42bea92de1 100644 --- a/c/windows.c +++ b/c/windows.c @@ -408,10 +408,14 @@ int S_windows_rename(const char *oldpathname, const char *newpathname) { int S_windows_rmdir(const char *pathname) { wchar_t wpathname[PATH_MAX]; + int rc; if (MultiByteToWideChar(CP_UTF8,0,pathname,-1,wpathname,PATH_MAX) == 0) - return _rmdir(pathname); + rc =_rmdir(pathname); else - return _wrmdir(wpathname); + rc = _wrmdir(wpathname); + if (0 == rc) + Sleep(0); // Give Windows time to delete the directory. + return rc; } int S_windows_stat64(const char *pathname, struct STATBUF *buffer) { @@ -432,10 +436,14 @@ int S_windows_system(const char *command) { int S_windows_unlink(const char *pathname) { wchar_t wpathname[PATH_MAX]; + int rc; if (MultiByteToWideChar(CP_UTF8,0,pathname,-1,wpathname,PATH_MAX) == 0) - return _unlink(pathname); + rc = _unlink(pathname); else - return _wunlink(wpathname); + rc = _wunlink(wpathname); + if (0 == rc) + Sleep(0); // Give Windows time to delete the file. + return rc; } char *S_windows_getcwd(char *buffer, int maxlen) { diff --git a/release_notes/release_notes.stex b/release_notes/release_notes.stex index 6e063883b9..1459130cfc 100644 --- a/release_notes/release_notes.stex +++ b/release_notes/release_notes.stex @@ -1542,6 +1542,14 @@ in fasl files does not generally make sense. %----------------------------------------------------------------------------- \section{Bug Fixes}\label{section:bugfixes} +\subsection{Permission denied after deleting files or directories in Windows} + +In Windows, deleting a file or directory briefly leaves the file or +directory in a state where a subsequent create operation fails with +permission denied. This race condition is now mitigated by a call to +Sleep. +[This bug applies to all versions up to 9.5 on Windows 7 and later.] + \subsection{Incorrect handling of offset in \protect\scheme{date->time-utc} on Windows (9.5)}