-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix problem with RemoveDirectory #129
Conversation
RemoveDirectory API exhibits a strange behaviour when removing a directory that is open. The directory is deleted and the API returns success, however calling RemoveDirectory for the parent directory immediately afterwards fails with "The directory is not empty." error. It appears that the directory deletion is completed asynchronously. This behaviour is not documented AFAIK but is easy to reproduce: 1. Create an empty directory tree c:\1\2 2. Open c:\1\2 in File Explorer 3. Run the following program: RemoveDirectory("c:\\1\\2"); RemoveDirectory("c:\\1"); The second RemoveDirectory fails with "The directory is not empty." even though the directory c:\1\2 has been removed. Adding a short delay between RemoveDirectory calls makes the second call succeed.
Hi, thanks for the pull request, I don't however think this is the right place for this. I believe such a change should be in a higher level library such as Also |
I first made the fix in
About delays:
|
There is no such thing in
As the issue I have pointed to above indicates the directory maintainer understands that such code belongs in directory as it deals with platform specific issues. And even there he would like it not to be the default mode of operation.
This is the documented behavior of the API. MSDN states
It is by design, as such And lastly For these reasons I won't be accepting these change in |
I've raised the issue in haskell/directory#129. |
Description
RemoveDirectory
API exhibits a strange behavior when removing adirectory that is open. The directory is deleted and the API returns
success, however calling
RemoveDirectory
on the parent directoryimmediately afterwards fails with
The directory is not empty.
error.It appears that the directory deletion is completed asynchronously. This
behaviour is not documented AFAIK but is easy to reproduce:
Create an empty directory tree
c:\1\2
Open
c:\1\2
in File ExplorerRun the following program:
The second
RemoveDirectory
fails withThe directory is not empty.
eventhough the directory
c:\1\2
has been removed. Adding a short delaybetween
RemoveDirectory
calls makes the second call succeed.There is no principled way to determine right delay. Experimentally even 20 us
was sufficient on my machine so 100 us seemed like a conservative number
that still isn't too long.
Motivation and Context
This problem is most apparent in
System.removeDirectoryRecursive
function which traverses a directory tree deleting files and then empty directories. If a directory is open by some process onthe system (e.g. anti-virus software) the function fails with
The directory is not empty.
error while leaving an empty directory on the system. Various Haskell projects have been plagued by low-frequency occurrence of this problem, e.g.:haskell/cabal#3123
haskell/cabal#3126
Euterpea/Euterpea2#18
Types of changes
Checklist:
Win32.cabal
.