LIB: various cleanups

This commit is contained in:
2016-04-06 03:10:07 +02:00
parent bad817d32d
commit 038b0d0377
5 changed files with 129 additions and 96 deletions

View File

@@ -158,14 +158,19 @@ doesDirectoryExist fp =
return $ PF.isDirectory fs
-- |Checks whether the directory at the given path exists and can be
-- opened. This invokes `openDirStream`.
canOpenDirectory :: Path Abs -> IO Bool
canOpenDirectory fp =
handleIOError (\_ -> return False) $ do
dirstream <- PFD.openDirStream . P.fromAbs $ fp
PFD.closeDirStream dirstream
bracket (PFD.openDirStream . P.fromAbs $ fp)
PFD.closeDirStream
(\_ -> return ())
return True
-- |Throws a `Can'tOpenDirectory` FmIOException if the directory at the given
-- path cannot be opened.
throwCantOpenDirectory :: Path Abs -> IO ()
throwCantOpenDirectory fp =
unlessM (canOpenDirectory fp)
@@ -194,6 +199,7 @@ catchErrno en a1 a2 =
else ioError e
-- |Like `catchIOError`, with arguments swapped.
handleIOError :: (IOError -> IO a) -> IO a -> IO a
handleIOError a1 a2 = catchIOError a2 a1