diff --git a/src/HSFM/FileSystem/Errors.hs b/src/HSFM/FileSystem/Errors.hs index 83a2ce7..591b176 100644 --- a/src/HSFM/FileSystem/Errors.hs +++ b/src/HSFM/FileSystem/Errors.hs @@ -199,6 +199,15 @@ catchErrno en a1 a2 = else ioError e +-- |Execute the given action and retrow IO exceptions that have the given errno. +rethrowErrnoAs :: Errno -- ^ errno to catch + -> FmIOException -- ^ rethrow as + -> IO a -- ^ action to try + -> IO a +rethrowErrnoAs en fmex action = catchErrno en action (throw fmex) + + + -- |Like `catchIOError`, with arguments swapped. handleIOError :: (IOError -> IO a) -> IO a -> IO a handleIOError a1 a2 = catchIOError a2 a1 diff --git a/src/HSFM/FileSystem/FileType.hs b/src/HSFM/FileSystem/FileType.hs index da770b0..26eee41 100644 --- a/src/HSFM/FileSystem/FileType.hs +++ b/src/HSFM/FileSystem/FileType.hs @@ -52,6 +52,10 @@ import Data.Time.Clock.POSIX , posixSecondsToUTCTime ) import Data.Time() +import Foreign.C.Error + ( + eACCES + ) import HPath ( Abs @@ -60,6 +64,7 @@ import HPath , pattern Path ) import qualified HPath as P +import HSFM.FileSystem.Errors import HSFM.Utils.MyPrelude import Prelude hiding(readFile) import System.IO.Error @@ -608,7 +613,8 @@ getDirsFiles' :: (Path Fn -> [Path Fn] -> [Path Fn]) -- ^ filter function -> Path Abs -- ^ dir to read -> IO [Path Fn] getDirsFiles' filterf fp = - bracket (PFD.openDirStream . P.toFilePath $ fp) + rethrowErrnoAs eACCES (Can'tOpenDirectory . P.fpToString . P.fromAbs $ fp) + $ bracket (PFD.openDirStream . P.toFilePath $ fp) PFD.closeDirStream $ \dirstream -> let mdirs :: [Path Fn] -> IO [Path Fn]