From: Erik Faye-Lund Date: Tue, 14 Dec 2010 22:49:17 GMT Subject: Re: [PATCH v3 5/5] mingw_rmdir: set errno=ENOTEMPTY when appropriate Message-ID: In-Reply-To: <20101214222830.GF4084@sandbox> On Tue, Dec 14, 2010 at 11:28 PM, Heiko Voigt wrote: > From: Johannes Schindelin > > On Windows, EACCES overrules ENOTEMPTY when calling rmdir(). But if the > directory is busy, we only want to retry deleting the directory if it > is empty, so test specifically for that case and set ENOTEMPTY rather > than EACCES. > Hmm... According to MSDN, rmdir(*) should already handle ENOTEMPTY. Isn't the problem rather the structure of that loop? Shouldn't it be sufficient to do something like this (note: untested, but the concept should work, no)? ---8<--- #undef rmdir int mingw_rmdir(const char *pathname) { int ret, tries; for (tries = 0; tries < ARRAY_SIZE(delay); ++tries) { if (!(ret = rmdir(pathname)) || errno == ENOTEMPTY || !is_file_in_use_error(GetLastError())) return ret; /* * We assume that some other process had the source or * destination file open at the wrong moment and retry. * In order to give the other process a higher chance to * complete its operation, we give up our time slice now. * If we have to retry again, we do sleep a bit. */ Sleep(delay[tries]); } while (is_file_in_use_error(GetLastError()) && ask_user_yes_no("Deletion of directory '%s' failed. " "Should I try again?", pathname)) ret = rmdir(pathname); return ret; } ---8<--- (*) http://msdn.microsoft.com/en-us/library/wt8es881(v=VS.80).aspx