Merge pull request #4 from nilcons-contrib/canonical
Add canonicalPath and canonicalName combinators
This commit is contained in:
commit
705e021bcb
1 changed files with 16 additions and 1 deletions
|
@ -90,6 +90,10 @@ module System.FilePath.Find (
|
||||||
, filePerms
|
, filePerms
|
||||||
, anyPerms
|
, anyPerms
|
||||||
|
|
||||||
|
-- ** Combinators for canonical path and name
|
||||||
|
, canonicalPath
|
||||||
|
, canonicalName
|
||||||
|
|
||||||
-- ** Combinators that operate on symbolic links
|
-- ** Combinators that operate on symbolic links
|
||||||
, readLink
|
, readLink
|
||||||
, followStatus
|
, followStatus
|
||||||
|
@ -117,7 +121,7 @@ import Control.Monad (foldM, forM, liftM, liftM2)
|
||||||
import Control.Monad.State (State, evalState, get)
|
import Control.Monad.State (State, evalState, get)
|
||||||
import Data.Bits (Bits, (.&.))
|
import Data.Bits (Bits, (.&.))
|
||||||
import Data.List (sort)
|
import Data.List (sort)
|
||||||
import System.Directory (getDirectoryContents)
|
import System.Directory (getDirectoryContents, canonicalizePath)
|
||||||
import System.FilePath ((</>), takeDirectory, takeExtension, takeFileName)
|
import System.FilePath ((</>), takeDirectory, takeExtension, takeFileName)
|
||||||
import System.FilePath.GlobPattern (GlobPattern, (~~), (/~))
|
import System.FilePath.GlobPattern (GlobPattern, (~~), (/~))
|
||||||
import System.IO (hPutStrLn, stderr)
|
import System.IO (hPutStrLn, stderr)
|
||||||
|
@ -341,6 +345,17 @@ fileName = takeFileName `liftM` filePath
|
||||||
directory :: FindClause FilePath
|
directory :: FindClause FilePath
|
||||||
directory = takeDirectory `liftM` 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')
|
-- | Run the given action in the 'IO' monad (using 'unsafePerformIO')
|
||||||
-- if the current file is a symlink. Hide errors by wrapping results
|
-- if the current file is a symlink. Hide errors by wrapping results
|
||||||
-- in the 'Maybe' monad.
|
-- in the 'Maybe' monad.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue