-
Notifications
You must be signed in to change notification settings - Fork 48
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 createDirectoryIfMissing function #10
Fix createDirectoryIfMissing function #10
Conversation
What was the original problem and how can it be reproduced? |
Oh, I guess this is about #4 |
Yes, it's about #4. |
Tbh, I'm not convinced this is a proper fix (yet)... |
@hvr What do you think or what do you mean by yet? I think the permission error could be handled differently, but it should be separate from the already exists error, and it shouldn't end in a |
@hvr Or maybe just remove the |
@jpvillaisaza I've been digging through the Git history, and stumbled over b513fe8 which was the commit where @dcoutts introduced that confusing The In any case, I'd like to better understand the reasoning behind b513fe8 before changing anything here. |
@hvr To be more precise, https://github.com/jpvillaisaza/directory/commit/f18994e8259593b8026fe02e438a6f5b76de8c1e could be reverted. The only modification would be https://github.com/jpvillaisaza/directory/commit/6d1fc9bb0e4e935f1eaceb61ef4bbb5984aec130, which could be discussed more. |
After a conversation with @dcoutts here's one suggestion how to fix it: createDir dir notExistHandler = do
r <- E.try $ createDirectory dir
case (r :: Either IOException ()) of
Right () -> return ()
Left e
| isDoesNotExistError e -> notExistHandler e
| isAlreadyExistsError e || isPermissionError e -> do
#ifdef mingw32_HOST_OS
canIgnore <- (withFileStatus "createDirectoryIfMissing" dir isDirectory)
#else
canIgnore <- (Posix.isDirectory `fmap` Posix.getFileStatus dir)
#endif
`catch` ((\ _ -> return False) :: IOException -> IO Bool)
unless canIgnore (throwIO e)
| otherwise -> throwIO e |
Ok, it's actually more subtle. It looks to me like we need to split the In the
while apparently in the
which actually is the same way round as the Why is this? Well, in the But for |
In some cases, `createDirectoryIfMissing` would silently fail. For example the following invocation would fail to report via an exception that it couldn't create a folder: let testdir = "/tmp/sometestdir" writeFile testdir "" createDirectoryIfMissing False testdir A related issue was the failure to create a folder hierarchy due to lack of permissions, for instance createDirectoryIfMissing True "/foo" for a non-priviledged user would silently fail (i.e. no exception thrown), even though "/foo" was not created. Fixes #4 (see also #10 for discussion)
This pull request is no longer necessary. See 1f11393. |
see #4