filepather 0.5 → 0.5.1
raw patch · 7 files changed
+142/−15 lines, 7 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- System.FilePath.FilePather.Find: findDirectories :: Exception e => ReadFilePathT e IO [FilePath]
+ System.FilePath.FilePather.Find: findAllDirectories :: Exception e => ReadFilePathT e IO [FilePath]
+ System.FilePath.FilePather.Find: findWith' :: Exception e => ReadFilePathT e IO Bool -> ReadFilePathT e IO [FilePath]
- System.FilePath.FilePather.Find: findWith :: Exception e => ReadFilePathT e IO Bool -> ReadFilePathT e IO [FilePath]
+ System.FilePath.FilePather.Find: findWith :: Exception e => ReadFilePathT e IO (Maybe b) -> ReadFilePathT e IO [b]
Files
- changelog.md +6/−0
- filepather.cabal +1/−1
- src/System/FilePath/FilePather/ByteString.hs +5/−0
- src/System/FilePath/FilePather/Directory.hs +46/−0
- src/System/FilePath/FilePather/Find.hs +33/−14
- src/System/FilePath/FilePather/IO.hs +12/−0
- src/System/FilePath/FilePather/Posix.hs +39/−0
changelog.md view
@@ -1,3 +1,9 @@+0.5.1++* Fix bug in `Find` module+* Add function to `Find` module+* `INLINE` definitions+ 0.5 * Introduce `Either` into filepath reader
filepather.cabal view
@@ -1,5 +1,5 @@ name: filepather-version: 0.5+version: 0.5.1 synopsis: Functions on System.FilePath description: Functions over @System.FilePath@ including a find function for recursing down directories.
src/System/FilePath/FilePather/ByteString.hs view
@@ -6,6 +6,7 @@ , readFileB , writeFileB , appendFileB+, module B ) where import Control.Exception ( Exception )@@ -20,12 +21,14 @@ ReadFilePathT e IO ByteString fromFilePath = tryReadFilePath B.fromFilePath+{-# INLINE fromFilePath #-} readFileB :: Exception e => ReadFilePathT e IO ByteString readFileB = tryReadFilePath B.readFile+{-# INLINE readFileB #-} writeFileB :: Exception e =>@@ -33,6 +36,7 @@ -> ReadFilePathT e IO () writeFileB s = tryReadFilePath (`B.writeFile` s)+{-# INLINE writeFileB #-} appendFileB :: Exception e =>@@ -40,3 +44,4 @@ -> ReadFilePathT e IO () appendFileB s = tryReadFilePath (`B.appendFile` s)+{-# INLINE appendFileB #-}
src/System/FilePath/FilePather/Directory.hs view
@@ -59,6 +59,10 @@ import qualified System.Directory as D import System.Directory as SD(getCurrentDirectory, getHomeDirectory, XdgDirectory(..), XdgDirectoryList(..), getXdgDirectoryList, getUserDocumentsDirectory, getTemporaryDirectory, exeExtension, Permissions(..), emptyPermissions, readable, writable, executable, searchable, setOwnerReadable, setOwnerWritable, setOwnerExecutable, setOwnerSearchable) import System.FilePath.FilePather.ReadFilePath+ ( ReadFilePathT1,+ ReadFilePathT,+ successReadFilePath,+ tryReadFilePath ) import System.FilePath ( FilePath ) import System.IO ( IO ) @@ -67,6 +71,7 @@ ReadFilePathT1 e IO createDirectory = tryReadFilePath D.createDirectory+{-# INLINE createDirectory #-} createDirectoryIfMissing :: Exception e =>@@ -74,24 +79,28 @@ -> ReadFilePathT1 e IO createDirectoryIfMissing = tryReadFilePath . D.createDirectoryIfMissing+{-# INLINE createDirectoryIfMissing #-} removeDirectory :: Exception e => ReadFilePathT1 e IO removeDirectory = tryReadFilePath D.removeDirectory+{-# INLINE removeDirectory #-} removeDirectoryRecursive :: Exception e => ReadFilePathT1 e IO removeDirectoryRecursive = tryReadFilePath D.removeDirectoryRecursive+{-# INLINE removeDirectoryRecursive #-} removePathForcibly :: Exception e => ReadFilePathT1 e IO removePathForcibly = tryReadFilePath D.removePathForcibly+{-# INLINE removePathForcibly #-} renameDirectory :: Exception e =>@@ -99,18 +108,21 @@ -> ReadFilePathT1 e IO renameDirectory = tryReadFilePath . D.renameDirectory+{-# INLINE renameDirectory #-} listDirectory :: Exception e => ReadFilePathT e IO [FilePath] listDirectory = tryReadFilePath D.listDirectory+{-# INLINE listDirectory #-} getDirectoryContents :: Exception e => ReadFilePathT e IO [FilePath] getDirectoryContents = tryReadFilePath D.listDirectory+{-# INLINE getDirectoryContents #-} withCurrentDirectory :: Exception e =>@@ -118,6 +130,7 @@ -> ReadFilePathT e IO a withCurrentDirectory io = tryReadFilePath (`D.withCurrentDirectory` io)+{-# INLINE withCurrentDirectory #-} getXdgDirectory :: Exception e =>@@ -125,18 +138,21 @@ -> ReadFilePathT e IO FilePath getXdgDirectory xdg = tryReadFilePath (D.getXdgDirectory xdg)+{-# INLINE getXdgDirectory #-} getAppUserDataDirectory :: Exception e => ReadFilePathT e IO FilePath getAppUserDataDirectory = tryReadFilePath D.getAppUserDataDirectory+{-# INLINE getAppUserDataDirectory #-} removeFile :: Exception e => ReadFilePathT1 e IO removeFile = tryReadFilePath D.removeFile+{-# INLINE removeFile #-} renameFile :: Exception e =>@@ -144,6 +160,7 @@ -> ReadFilePathT1 e IO renameFile = tryReadFilePath . D.renameFile+{-# INLINE renameFile #-} renamePath :: Exception e =>@@ -151,6 +168,7 @@ -> ReadFilePathT1 e IO renamePath = tryReadFilePath . D.renamePath+{-# INLINE renamePath #-} copyFile :: Exception e =>@@ -158,6 +176,7 @@ -> ReadFilePathT1 e IO copyFile = tryReadFilePath . D.copyFile+{-# INLINE copyFile #-} copyFileWithMetadata :: Exception e =>@@ -165,73 +184,86 @@ -> ReadFilePathT1 e IO copyFileWithMetadata = tryReadFilePath . D.copyFileWithMetadata+{-# INLINE copyFileWithMetadata #-} getFileSize :: Exception e => ReadFilePathT e IO Integer getFileSize = tryReadFilePath D.getFileSize+{-# INLINE getFileSize #-} canonicalizePath :: Exception e => ReadFilePathT e IO FilePath canonicalizePath = tryReadFilePath D.canonicalizePath+{-# INLINE canonicalizePath #-} makeAbsolute :: Exception e => ReadFilePathT e IO FilePath makeAbsolute = tryReadFilePath D.makeAbsolute+{-# INLINE makeAbsolute #-} makeRelativeToCurrentDirectory :: Exception e => ReadFilePathT e IO FilePath makeRelativeToCurrentDirectory = tryReadFilePath D.makeRelativeToCurrentDirectory+{-# INLINE makeRelativeToCurrentDirectory #-} doesPathExist :: ReadFilePathT e IO Bool doesPathExist = successReadFilePath D.doesPathExist+{-# INLINE doesPathExist #-} doesFileExist :: ReadFilePathT e IO Bool doesFileExist = successReadFilePath D.doesFileExist+{-# INLINE doesFileExist #-} doesDirectoryExist :: ReadFilePathT e IO Bool doesDirectoryExist = successReadFilePath D.doesDirectoryExist+{-# INLINE doesDirectoryExist #-} findExecutable :: ReadFilePathT e IO (Maybe FilePath) findExecutable = successReadFilePath D.findExecutable+{-# INLINE findExecutable #-} findExecutables :: ReadFilePathT e IO [FilePath] findExecutables = successReadFilePath D.findExecutables+{-# INLINE findExecutables #-} findExecutablesInDirectories :: [FilePath] -> ReadFilePathT e IO [FilePath] findExecutablesInDirectories = successReadFilePath . D.findExecutablesInDirectories+{-# INLINE findExecutablesInDirectories #-} findFile :: [FilePath] -> ReadFilePathT e IO (Maybe FilePath) findFile = successReadFilePath . D.findFile+{-# INLINE findFile #-} findFiles :: [FilePath] -> ReadFilePathT e IO [FilePath] findFiles = successReadFilePath . D.findFiles+{-# INLINE findFiles #-} findFileWith :: ReadFilePathT () IO ()@@ -239,6 +271,7 @@ -> ReadFilePathT () IO FilePath findFileWith x ps = over _Wrapped (\k -> fmap (maybe (Left ()) Right) . D.findFileWith (fmap (either (\() -> False) (\() -> True)) . k) ps) x+{-# INLINE findFileWith #-} findFilesWith :: ReadFilePathT () IO ()@@ -246,6 +279,7 @@ -> ReadFilePathT e' IO [FilePath] findFilesWith x ps = over _Wrapped (\w -> fmap Right . D.findFilesWith (fmap (either (\() -> False) (\() -> True)) . w) ps) x+{-# INLINE findFilesWith #-} createFileLink :: Exception e =>@@ -253,6 +287,7 @@ -> ReadFilePathT1 e IO createFileLink = tryReadFilePath . D.createFileLink+{-# INLINE createFileLink #-} createDirectoryLink :: Exception e =>@@ -260,30 +295,35 @@ -> ReadFilePathT1 e IO createDirectoryLink = tryReadFilePath . D.createDirectoryLink+{-# INLINE createDirectoryLink #-} removeDirectoryLink :: Exception e => ReadFilePathT1 e IO removeDirectoryLink = tryReadFilePath D.removeDirectoryLink+{-# INLINE removeDirectoryLink #-} pathIsSymbolicLink :: Exception e => ReadFilePathT e IO Bool pathIsSymbolicLink = tryReadFilePath D.pathIsSymbolicLink+{-# INLINE pathIsSymbolicLink #-} getSymbolicLinkTarget :: Exception e => ReadFilePathT e IO FilePath getSymbolicLinkTarget = tryReadFilePath D.getSymbolicLinkTarget+{-# INLINE getSymbolicLinkTarget #-} getPermissions :: Exception e => ReadFilePathT e IO Permissions getPermissions = tryReadFilePath D.getPermissions+{-# INLINE getPermissions #-} setPermissions :: Exception e =>@@ -291,6 +331,7 @@ -> ReadFilePathT1 e IO setPermissions p = tryReadFilePath (`D.setPermissions` p)+{-# INLINE setPermissions #-} copyPermissions :: Exception e =>@@ -298,18 +339,21 @@ -> ReadFilePathT1 e IO copyPermissions = tryReadFilePath . D.copyPermissions+{-# INLINE copyPermissions #-} getAccessTime :: Exception e => ReadFilePathT e IO UTCTime getAccessTime = tryReadFilePath D.getAccessTime+{-# INLINE getAccessTime #-} getModificationTime :: Exception e => ReadFilePathT e IO UTCTime getModificationTime = tryReadFilePath D.getModificationTime+{-# INLINE getModificationTime #-} setAccessTime :: Exception e =>@@ -317,6 +361,7 @@ -> ReadFilePathT1 e IO setAccessTime u = tryReadFilePath (`D.setAccessTime` u)+{-# INLINE setAccessTime #-} setModificationTime :: Exception e =>@@ -324,3 +369,4 @@ -> ReadFilePathT1 e IO setModificationTime u = tryReadFilePath (`D.setModificationTime` u)+{-# INLINE setModificationTime #-}
src/System/FilePath/FilePather/Find.hs view
@@ -3,7 +3,8 @@ module System.FilePath.FilePather.Find( findWith-, findDirectories+, findWith'+, findAllDirectories , findAll , findAllFiles ) where@@ -11,13 +12,15 @@ import Control.Applicative ( Applicative(pure) ) import Control.Category ( Category((.)) ) import Control.Exception ( Exception )-import Control.Lens ( view, _Wrapped )+import Control.Lens ( view, _Wrapped, _1, _2 ) import Control.Monad ( Monad((>>=)), filterM ) import Control.Monad.IO.Class ( MonadIO(liftIO) )-import Control.Monad.Reader ( MonadReader(local, ask) )-import Data.Bool ( Bool(True) )+import Control.Monad.Reader+ ( MonadReader(local, ask) )+import Data.Bool ( Bool(True), bool ) import Data.Foldable ( fold ) import Data.Functor ( Functor(fmap), (<$>) )+import Data.Maybe ( Maybe(..), catMaybes ) import Data.Semigroup ( Semigroup((<>)) ) import Data.Traversable ( Traversable(traverse) ) import System.FilePath ( FilePath, (</>) )@@ -29,36 +32,52 @@ findWith :: Exception e =>- ReadFilePathT e IO Bool- -> ReadFilePathT e IO [FilePath]+ ReadFilePathT e IO (Maybe b)+ -> ReadFilePathT e IO [b] findWith p = let setl = local . pure+ mapMaybeM f xs =+ catMaybes <$> traverse f xs in do z <- ask a <- listDirectory- b <- filterM (`setl` p) ((z </>) <$> a)- d <- filterM (`setl` doesDirectoryExist) b+ let y = (z </>) <$> a+ b <- mapMaybeM (\fp -> fmap (fmap (\s -> (s, fp))) (fp `setl` p)) y+ d <- filterM (`setl` doesDirectoryExist) (fmap (view _2) b)+ let bs = fmap (view _1) b case d of [] ->- pure b+ pure bs _ -> do n <- liftIO (unsafeInterleaveIO (fmap (>>= fold) (traverse (view _Wrapped (findWith p)) d)))- pure (b <> n)+ pure (bs <> n)+{-# INLINE findWith #-} -findDirectories ::+findWith' :: Exception e =>+ ReadFilePathT e IO Bool+ -> ReadFilePathT e IO [FilePath]+findWith' s =+ findWith (ask >>= \d -> fmap (bool Nothing (Just d)) s)+{-# INLINE findWith' #-}++findAllDirectories ::+ Exception e => ReadFilePathT e IO [FilePath]-findDirectories =- findWith doesDirectoryExist+findAllDirectories =+ findWith' doesDirectoryExist+{-# INLINE findAllDirectories #-} findAll :: Exception e => ReadFilePathT e IO [FilePath] findAll =- findWith (pure True)+ findWith' (pure True)+{-# INLINE findAll #-} findAllFiles :: Exception e => ReadFilePathT e IO [FilePath] findAllFiles = findAll >>= filterM (\p -> local (pure p) doesFileExist)+{-# INLINE findAllFiles #-}
src/System/FilePath/FilePather/IO.hs view
@@ -41,12 +41,14 @@ ReadFilePathT e IO String readFile = tryReadFilePath I.readFile+{-# INLINE readFile #-} readFile' :: Exception e => ReadFilePathT e IO String readFile' = tryReadFilePath I.readFile'+{-# INLINE readFile' #-} appendFile :: Exception e =>@@ -54,6 +56,7 @@ -> ReadFilePathT e IO () appendFile s = tryReadFilePath (`I.appendFile` s)+{-# INLINE appendFile #-} writeFile :: Exception e =>@@ -61,6 +64,7 @@ -> ReadFilePathT e IO () writeFile s = tryReadFilePath (`I.writeFile` s)+{-# INLINE writeFile #-} withFile :: Exception e =>@@ -69,6 +73,7 @@ -> ReadFilePathT e IO r withFile mode k = tryReadFilePath (\p -> I.withFile p mode k)+{-# INLINE withFile #-} openFile :: Exception e =>@@ -76,6 +81,7 @@ -> ReadFilePathT e IO Handle openFile mode = tryReadFilePath (`I.openFile` mode)+{-# INLINE openFile #-} withBinaryFile :: Exception e =>@@ -84,6 +90,7 @@ -> ReadFilePathT e IO r withBinaryFile mode k = tryReadFilePath (\p -> I.withBinaryFile p mode k)+{-# INLINE withBinaryFile #-} openBinaryFile :: Exception e =>@@ -91,6 +98,7 @@ -> ReadFilePathT e IO Handle openBinaryFile mode = tryReadFilePath (`I.openBinaryFile` mode)+{-# INLINE openBinaryFile #-} openTempFile :: Exception e =>@@ -98,6 +106,7 @@ -> ReadFilePathT e IO (FilePath, Handle) openTempFile s = tryReadFilePath (`I.openTempFile` s)+{-# INLINE openTempFile #-} openBinaryTempFile :: Exception e =>@@ -105,6 +114,7 @@ -> ReadFilePathT e IO (FilePath, Handle) openBinaryTempFile s = tryReadFilePath (`I.openBinaryTempFile` s)+{-# INLINE openBinaryTempFile #-} openTempFileWithDefaultPermissions :: Exception e =>@@ -112,6 +122,7 @@ -> ReadFilePathT e IO (FilePath, Handle) openTempFileWithDefaultPermissions s = tryReadFilePath (`I.openTempFileWithDefaultPermissions` s)+{-# INLINE openTempFileWithDefaultPermissions #-} openBinaryTempFileWithDefaultPermissions :: Exception e =>@@ -119,3 +130,4 @@ -> ReadFilePathT e IO (FilePath, Handle) openBinaryTempFileWithDefaultPermissions s = tryReadFilePath (`I.openBinaryTempFileWithDefaultPermissions` s)+{-# INLINE openBinaryTempFileWithDefaultPermissions #-}
src/System/FilePath/FilePather/Posix.hs view
@@ -59,12 +59,14 @@ ReadFilePathT e f (String, String) splitExtension = liftReadFilePath FP.splitExtension+{-# INLINE splitExtension #-} takeExtension :: Applicative f => ReadFilePathT e f String takeExtension = liftReadFilePath FP.takeExtension+{-# INLINE takeExtension #-} replaceExtension :: Applicative f =>@@ -72,12 +74,14 @@ -> ReadFilePathT e f FilePath replaceExtension = liftReadFilePath . FP.replaceExtension+{-# INLINE replaceExtension #-} dropExtension :: Applicative f => ReadFilePathT e f FilePath dropExtension = liftReadFilePath FP.dropExtensions+{-# INLINE dropExtension #-} addExtension :: Applicative f =>@@ -85,30 +89,35 @@ -> ReadFilePathT e f FilePath addExtension = liftReadFilePath . FP.addExtension+{-# INLINE addExtension #-} hasExtension :: Applicative f => ReadFilePathT e f Bool hasExtension = liftReadFilePath FP.hasExtension+{-# INLINE hasExtension #-} splitExtensions :: Applicative f => ReadFilePathT e f (FilePath, String) splitExtensions = liftReadFilePath FP.splitExtensions+{-# INLINE splitExtensions #-} dropExtensions :: Applicative f => ReadFilePathT e f FilePath dropExtensions = liftReadFilePath FP.dropExtensions+{-# INLINE dropExtensions #-} takeExtensions :: Applicative f => ReadFilePathT e f String takeExtensions = liftReadFilePath FP.takeExtensions+{-# INLINE takeExtensions #-} replaceExtensions :: Applicative f =>@@ -116,6 +125,7 @@ -> ReadFilePathT e f FilePath replaceExtensions = liftReadFilePath . FP.replaceExtensions+{-# INLINE replaceExtensions #-} isExtensionOf :: Applicative f =>@@ -123,6 +133,7 @@ -> ReadFilePathT e f Bool isExtensionOf = liftReadFilePath . FP.isExtensionOf+{-# INLINE isExtensionOf #-} stripExtension :: Applicative f =>@@ -130,18 +141,21 @@ -> ReadFilePathT e f (Maybe FilePath) stripExtension = liftReadFilePath . FP.stripExtension+{-# INLINE stripExtension #-} splitFileName :: Applicative f => ReadFilePathT e f (String, String) splitFileName = liftReadFilePath FP.splitFileName+{-# INLINE splitFileName #-} takeFileName :: Applicative f => ReadFilePathT e f String takeFileName = liftReadFilePath FP.takeFileName+{-# INLINE takeFileName #-} replaceFileName :: Applicative f =>@@ -149,18 +163,21 @@ -> ReadFilePathT e f FilePath replaceFileName = liftReadFilePath . FP.replaceFileName+{-# INLINE replaceFileName #-} dropFileName :: Applicative f => ReadFilePathT e f FilePath dropFileName = liftReadFilePath FP.dropFileName+{-# INLINE dropFileName #-} takeBaseName :: Applicative f => ReadFilePathT e f String takeBaseName = liftReadFilePath FP.takeBaseName+{-# INLINE takeBaseName #-} replaceBaseName :: Applicative f =>@@ -168,12 +185,14 @@ ReadFilePathT e f FilePath replaceBaseName = liftReadFilePath . FP.replaceBaseName+{-# INLINE replaceBaseName #-} takeDirectory :: Applicative f => ReadFilePathT e f FilePath takeDirectory = liftReadFilePath FP.takeDirectory+{-# INLINE takeDirectory #-} replaceDirectory :: Applicative f =>@@ -181,6 +200,7 @@ ReadFilePathT e f FilePath replaceDirectory = liftReadFilePath . FP.replaceDirectory+{-# INLINE replaceDirectory #-} combine :: Applicative f =>@@ -188,24 +208,28 @@ -> ReadFilePathT e f FilePath combine = liftReadFilePath . FP.combine+{-# INLINE combine #-} splitPath :: Applicative f => ReadFilePathT e f [FilePath] splitPath = liftReadFilePath FP.splitPath+{-# INLINE splitPath #-} splitDirectories :: Applicative f => ReadFilePathT e f [FilePath] splitDirectories = liftReadFilePath FP.splitDirectories+{-# INLINE splitDirectories #-} splitDrive :: Applicative f => ReadFilePathT e f (FilePath, FilePath) splitDrive = liftReadFilePath FP.splitDrive+{-# INLINE splitDrive #-} joinDrive :: Applicative f =>@@ -213,54 +237,63 @@ -> ReadFilePathT e f FilePath joinDrive = liftReadFilePath . FP.joinDrive+{-# INLINE joinDrive #-} takeDrive :: Applicative f => ReadFilePathT e f FilePath takeDrive = liftReadFilePath FP.takeDrive+{-# INLINE takeDrive #-} hasDrive :: Applicative f => ReadFilePathT e f Bool hasDrive = liftReadFilePath FP.hasDrive+{-# INLINE hasDrive #-} dropDrive :: Applicative f => ReadFilePathT e f FilePath dropDrive = liftReadFilePath FP.dropDrive+{-# INLINE dropDrive #-} isDrive :: Applicative f => ReadFilePathT e f Bool isDrive = liftReadFilePath FP.isDrive+{-# INLINE isDrive #-} hasTrailingPathSeparator :: Applicative f => ReadFilePathT e f Bool hasTrailingPathSeparator = liftReadFilePath FP.hasTrailingPathSeparator+{-# INLINE hasTrailingPathSeparator #-} addTrailingPathSeparator :: Applicative f => ReadFilePathT e f FilePath addTrailingPathSeparator = liftReadFilePath FP.addTrailingPathSeparator+{-# INLINE addTrailingPathSeparator #-} dropTrailingPathSeparator :: Applicative f => ReadFilePathT e f FilePath dropTrailingPathSeparator = liftReadFilePath FP.dropTrailingPathSeparator+{-# INLINE dropTrailingPathSeparator #-} normalise :: Applicative f => ReadFilePathT e f FilePath normalise = liftReadFilePath FP.normalise+{-# INLINE normalise #-} equalFilePath :: Applicative f =>@@ -268,6 +301,7 @@ -> ReadFilePathT e f Bool equalFilePath = liftReadFilePath . FP.equalFilePath+{-# INLINE equalFilePath #-} makeRelative :: Applicative f =>@@ -275,27 +309,32 @@ -> ReadFilePathT e f FilePath makeRelative = liftReadFilePath . FP.makeRelative+{-# INLINE makeRelative #-} isRelative :: Applicative f => ReadFilePathT e f Bool isRelative = liftReadFilePath FP.isRelative+{-# INLINE isRelative #-} isAbsolute :: Applicative f => ReadFilePathT e f Bool isAbsolute = liftReadFilePath FP.isAbsolute+{-# INLINE isAbsolute #-} isValid :: Applicative f => ReadFilePathT e f Bool isValid = liftReadFilePath FP.isValid+{-# INLINE isValid #-} makeValid :: Applicative f => ReadFilePathT e f FilePath makeValid = liftReadFilePath FP.makeValid+{-# INLINE makeValid #-}