LIB: add canOpenDirectory and throwCantOpenDirectory

This commit is contained in:
Julian Ospald 2016-04-03 14:32:10 +02:00
parent b6342068f2
commit d8fc529bf1
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28

View File

@ -51,6 +51,7 @@ import System.IO.Error
)
import qualified System.Posix.Files as PF
import qualified System.Posix.Directory as PFD
data FmIOException = FileDoesNotExist String
@ -66,6 +67,7 @@ data FmIOException = FileDoesNotExist String
| IsSymlink String
| InvalidOperation String
| InvalidFileName
| Can'tOpenDirectory String
deriving (Show, Typeable)
@ -139,6 +141,18 @@ doesDirectoryExist fp =
return $ PF.isDirectory fs
canOpenDirectory :: Path Abs -> IO Bool
canOpenDirectory fp =
handleIOError (\_ -> return False) $ do
dirstream <- PFD.openDirStream . P.fromAbs $ fp
PFD.closeDirStream dirstream
return True
throwCantOpenDirectory :: Path Abs -> IO ()
throwCantOpenDirectory fp =
unlessM (canOpenDirectory fp) (throw $ Can'tOpenDirectory $ P.fromAbs fp)
--------------------------------