Add canonicalPath and canonicalName combinators

This commit is contained in:
Mihaly Barasz 2014-04-05 22:26:53 +02:00
parent 41cd3ac887
commit 97afb2427d
1 changed files with 16 additions and 1 deletions

View File

@ -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.