Fix createDirectoryIfMissing to not throw if the dir got deleted
authorDuncan Coutts <duncan@haskell.org>
Mon, 22 Dec 2008 16:41:05 +0000 (16:41 +0000)
committerDuncan Coutts <duncan@haskell.org>
Mon, 22 Dec 2008 16:41:05 +0000 (16:41 +0000)
commitb513fe8c184b758a71dc7c7d0accaabdaf7797f0
treeb1cbb9aa42306c672de0740a62fd51939dcf5420
parent89a23b69a350a01be9e14154c1e9d3587241b9af
Fix createDirectoryIfMissing to not throw if the dir got deleted
When we call createDirectory and some file system object already exists
we have a problem. We need to distinguish if it is a file that already
exists or if it is a directory because in the latter case it is not an
error. Previously we called doesDirectoryExist however that does not
distinguish the dir not existing (due to another thread deleting it)
and an ordinary file existing. We now use withFileStatus to throw the
original AlreadyExistsError only if a non-directory object exists.
So now the only time we should get a spurious exception is if another
thread deletes the directory and puts a file in its place between our
call to createDirectory and withFileStatus. It should now be safe to
race createDirectoryIfMissing with itself or deleteDirectoryRecursive.
System/Directory.hs