LIB: add canOpenDirectory and throwCantOpenDirectory
This commit is contained in:
parent
b6342068f2
commit
d8fc529bf1
@ -51,6 +51,7 @@ import System.IO.Error
|
|||||||
)
|
)
|
||||||
|
|
||||||
import qualified System.Posix.Files as PF
|
import qualified System.Posix.Files as PF
|
||||||
|
import qualified System.Posix.Directory as PFD
|
||||||
|
|
||||||
|
|
||||||
data FmIOException = FileDoesNotExist String
|
data FmIOException = FileDoesNotExist String
|
||||||
@ -66,6 +67,7 @@ data FmIOException = FileDoesNotExist String
|
|||||||
| IsSymlink String
|
| IsSymlink String
|
||||||
| InvalidOperation String
|
| InvalidOperation String
|
||||||
| InvalidFileName
|
| InvalidFileName
|
||||||
|
| Can'tOpenDirectory String
|
||||||
deriving (Show, Typeable)
|
deriving (Show, Typeable)
|
||||||
|
|
||||||
|
|
||||||
@ -139,6 +141,18 @@ doesDirectoryExist fp =
|
|||||||
return $ PF.isDirectory fs
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user