diff --git a/System/FilePath/Find.hs b/System/FilePath/Find.hs index 2af3bd6..f2e5ed8 100644 --- a/System/FilePath/Find.hs +++ b/System/FilePath/Find.hs @@ -29,7 +29,7 @@ -- Because 'FindClause' is a monad, you can use the usual monad -- machinery to, for example, lift pure functions into it. -- --- Here's a clause that will return 'False' for any file whose +-- Here's a clause that will return 'True' for any file whose -- directory name contains the word @\"temp\"@. -- -- @ @@ -90,6 +90,10 @@ module System.FilePath.Find ( , filePerms , anyPerms + -- ** Combinators for canonical path and name + , canonicalPath + , canonicalName + -- ** Combinators that operate on symbolic links , readLink , followStatus @@ -117,7 +121,7 @@ import Control.Monad (foldM, forM, liftM, liftM2) import Control.Monad.State (State, evalState, get) import Data.Bits (Bits, (.&.)) import Data.List (sort) -import System.Directory (getDirectoryContents) +import System.Directory (getDirectoryContents, canonicalizePath) import System.FilePath ((), takeDirectory, takeExtension, takeFileName) import System.FilePath.GlobPattern (GlobPattern, (~~), (/~)) import System.IO (hPutStrLn, stderr) @@ -341,6 +345,17 @@ fileName = takeFileName `liftM` filePath directory :: FindClause FilePath directory = takeDirectory `liftM` filePath +-- | Return the canonical path of the file being visited. +-- +-- See `canonicalizePath` for details of what canonical path means. +canonicalPath :: FindClause FilePath +canonicalPath = (unsafePerformIO . canonicalizePath) `liftM` filePath + +-- | Return the canonical name of the file (canonical path with the +-- directory part removed). +canonicalName :: FindClause FilePath +canonicalName = takeFileName `liftM` canonicalPath + -- | Run the given action in the 'IO' monad (using 'unsafePerformIO') -- if the current file is a symlink. Hide errors by wrapping results -- in the 'Maybe' monad. diff --git a/System/FilePath/GlobPattern.hs b/System/FilePath/GlobPattern.hs index 37af02a..53903ac 100644 --- a/System/FilePath/GlobPattern.hs +++ b/System/FilePath/GlobPattern.hs @@ -152,7 +152,7 @@ matchTerms (MatchAny:ts) cs = matchAny cs >>= matchTerms ts where matchAny [] = fail "no match" matchAny cs' = case matchTerms ts cs' of Nothing -> matchAny (tail cs') - _ -> return cs + _ -> return cs' matchTerms [MatchDir] cs | pathSeparator `elem` cs = fail "path separator" | otherwise = return () matchTerms (MatchDir:ts) cs = matchDir cs >>= matchTerms ts diff --git a/examples/Simple.hs b/examples/Simple.hs index b49fc9c..850571f 100644 --- a/examples/Simple.hs +++ b/examples/Simple.hs @@ -33,7 +33,7 @@ renameCppToC path = find always (extension ==? ".cpp") path >>= noRCS :: RecursionPredicate -noRCS = (`elem` ["_darcs","SCCS","CVS",".svn",".hg",".git"]) `liftM` fileName +noRCS = (`notElem` ["_darcs","SCCS","CVS",".svn",".hg",".git"]) `liftM` fileName cSources :: FilePath -> IO [FilePath]