packages feed

FileManipCompat 0.12 → 0.13

raw patch · 2 files changed

+109/−3 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ System.FilePath.FindCompat: (&&?) :: FindClause Bool -> FindClause Bool -> FindClause Bool
+ System.FilePath.FindCompat: (.&.?) :: (Bits a) => FindClause a -> a -> FindClause a
+ System.FilePath.FindCompat: (/=?) :: (Eq a) => FindClause a -> a -> FindClause Bool
+ System.FilePath.FindCompat: (<=?) :: (Ord a) => FindClause a -> a -> FindClause Bool
+ System.FilePath.FindCompat: (<?) :: (Ord a) => FindClause a -> a -> FindClause Bool
+ System.FilePath.FindCompat: (==?) :: (Eq a) => FindClause a -> a -> FindClause Bool
+ System.FilePath.FindCompat: (>=?) :: (Ord a) => FindClause a -> a -> FindClause Bool
+ System.FilePath.FindCompat: (>?) :: (Ord a) => FindClause a -> a -> FindClause Bool
+ System.FilePath.FindCompat: (||?) :: FindClause Bool -> FindClause Bool -> FindClause Bool
+ System.FilePath.FindCompat: BlockDevice :: FileType
+ System.FilePath.FindCompat: CharacterDevice :: FileType
+ System.FilePath.FindCompat: Directory :: FileType
+ System.FilePath.FindCompat: FC :: State FileInfo a -> FindClause a
+ System.FilePath.FindCompat: FileInfo :: FilePath -> Int -> FileStatus -> FileInfo
+ System.FilePath.FindCompat: NamedPipe :: FileType
+ System.FilePath.FindCompat: RegularFile :: FileType
+ System.FilePath.FindCompat: Socket :: FileType
+ System.FilePath.FindCompat: SymbolicLink :: FileType
+ System.FilePath.FindCompat: Unknown :: FileType
+ System.FilePath.FindCompat: data FileInfo
+ System.FilePath.FindCompat: data FileType
+ System.FilePath.FindCompat: evalClause :: FindClause a -> FileInfo -> a
+ System.FilePath.FindCompat: evalFI :: FindClause a -> FilePath -> Int -> FileStatus -> a
+ System.FilePath.FindCompat: fileInfo :: FindClause FileInfo
+ System.FilePath.FindCompat: filePath :: FindClause FilePath
+ System.FilePath.FindCompat: fileStatus :: FindClause FileStatus
+ System.FilePath.FindCompat: fileType :: FindClause FileType
+ System.FilePath.FindCompat: findWithHandler :: (FilePath -> SomeException -> IO [FilePath]) -> RecursionPredicate -> FilterPredicate -> FilePath -> IO [FilePath]
+ System.FilePath.FindCompat: getDirContents :: FilePath -> IO [FilePath]
+ System.FilePath.FindCompat: infoDepth :: FileInfo -> Int
+ System.FilePath.FindCompat: infoPath :: FileInfo -> FilePath
+ System.FilePath.FindCompat: infoStatus :: FileInfo -> FileStatus
+ System.FilePath.FindCompat: instance Eq FileType
+ System.FilePath.FindCompat: instance Ord FileType
+ System.FilePath.FindCompat: instance Show FileType
+ System.FilePath.FindCompat: liftOp :: (Monad m) => (a -> b -> c) -> m a -> b -> m c
+ System.FilePath.FindCompat: mkFI :: FilePath -> Int -> FileStatus -> FileInfo
+ System.FilePath.FindCompat: mkFindClause :: (FileInfo -> (a, FileInfo)) -> FindClause a
+ System.FilePath.FindCompat: newtype FindClause a
+ System.FilePath.FindCompat: runFC :: FindClause a -> State FileInfo a
+ System.FilePath.FindCompat: statusType :: FileStatus -> FileType
+ System.FilePath.FindCompat: type FilterPredicate = FindClause Bool
+ System.FilePath.FindCompat: type RecursionPredicate = FindClause Bool

Files

FileManipCompat.cabal view
@@ -1,5 +1,5 @@ Name:               FileManipCompat-Version:            0.12+Version:            0.13 License:            BSD3 License-File:       LICENSE Author:             Bryan O'Sullivan <bos@serpentine.com>
System/FilePath/FindCompat.hs view
@@ -4,7 +4,7 @@ -- which was derived from FileManip package, which only works on unix. -- happstack port works on windows as well. -- repackage here as standalone to remove dependency on happstack, for immediate use with HStringTemplateHelpers.-module System.FilePath.FindCompat (always,find) where+module System.FilePath.FindCompat where  import qualified System.PosixCompat.Files as F import Control.Monad.State@@ -14,7 +14,7 @@ import System.Directory (getDirectoryContents) import System.IO.Unsafe (unsafeInterleaveIO) import System.FilePath ((</>))-+import Data.Bits (Bits, (.&.))  -- | Information collected during the traversal of a directory. data FileInfo = FileInfo@@ -26,6 +26,39 @@ instance Eq F.FileStatus where     a == b = F.deviceID a == F.deviceID b && F.fileID a == F.fileID b  +data FileType = BlockDevice+              | CharacterDevice+              | NamedPipe+              | RegularFile+              | Directory+              | SymbolicLink+              | Socket+              | Unknown+                deriving (Eq, Ord, Show)++-- | Return the type of file currently being visited.+--+-- Example:+--+-- @+-- 'fileType' '==?' 'RegularFile'+-- @+fileType :: FindClause FileType+fileType = statusType `liftM` fileStatus++-- | Return the type of a file.  This is much more useful for case+-- analysis than the usual functions on 'F.FileStatus' values.+statusType :: F.FileStatus -> FileType++statusType st | F.isBlockDevice st = BlockDevice+statusType st | F.isCharacterDevice st = CharacterDevice+statusType st | F.isNamedPipe st = NamedPipe+statusType st | F.isRegularFile st = RegularFile+statusType st | F.isDirectory st = Directory+statusType st | F.isSymbolicLink st = SymbolicLink+statusType st | F.isSocket st = Socket+statusType _ = Unknown+ -- | Construct a 'FileInfo' value.  mkFI :: FilePath -> Int -> F.FileStatus -> FileInfo@@ -61,6 +94,18 @@        -> a evalFI m p d s = evalClause m (mkFI p d s) +mkFindClause :: (FileInfo -> (a, FileInfo)) -> FindClause a+mkFindClause = FC . State++-- | Return the current 'FileInfo'.+fileInfo :: FindClause FileInfo+fileInfo = mkFindClause $ \st -> (st, st)+++-- | Return the 'F.FileStatus' for the current file.+fileStatus :: FindClause F.FileStatus+fileStatus = infoStatus `liftM` fileInfo+ type FilterPredicate = FindClause Bool type RecursionPredicate = FindClause Bool @@ -119,3 +164,64 @@ always :: FindClause Bool always = return True +-- | Return the name of the file being visited.+filePath :: FindClause FilePath++filePath = infoPath `liftM` fileInfo+++-- | Lift a binary operator into the 'FindClause' monad, so that it+-- becomes a combinator.  The left hand side of the combinator should+-- be a @'FindClause' a@, while the right remains a normal value of+-- type @a@.+liftOp :: Monad m => (a -> b -> c) -> m a -> b -> m c++liftOp f a b = a >>= \a' -> return (f a' b)++-- $binaryOperators+-- +-- These are lifted versions of the most commonly used binary+-- operators.  They have the same fixities and associativities as+-- their unlifted counterparts.  They are lifted using 'liftOp', like+-- so:+-- +-- @('==?') = 'liftOp' (==)@+++(==?) :: Eq a => FindClause a -> a -> FindClause Bool+(==?) = liftOp (==)+infix 4 ==?++(/=?) :: Eq a => FindClause a -> a -> FindClause Bool+(/=?) = liftOp (/=)+infix 4 /=?++(>?) :: Ord a => FindClause a -> a -> FindClause Bool+(>?) = liftOp (>)+infix 4 >?++(<?) :: Ord a => FindClause a -> a -> FindClause Bool+(<?) = liftOp (<)+infix 4 <?++(>=?) :: Ord a => FindClause a -> a -> FindClause Bool+(>=?) = liftOp (>=)+infix 4 >=?++(<=?) :: Ord a => FindClause a -> a -> FindClause Bool+(<=?) = liftOp (<=)+infix 4 <=?++-- | This operator is useful to check if bits are set in a+-- 'T.FileMode'.+(.&.?) :: Bits a => FindClause a -> a -> FindClause a+(.&.?) = liftOp (.&.)+infixl 7 .&.?++(&&?) :: FindClause Bool -> FindClause Bool -> FindClause Bool+(&&?) = liftM2 (&&)+infixr 3 &&?++(||?) :: FindClause Bool -> FindClause Bool -> FindClause Bool+(||?) = liftM2 (||)+infixr 2 ||?