Add withAbsPath/withRelPath/withFnPath

This commit is contained in:
Julian Ospald 2016-04-17 18:09:50 +02:00
parent a5360f29a3
commit 45b515d1db
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28

View File

@ -43,6 +43,10 @@ module HPath
,isParentOf ,isParentOf
,getAllParents ,getAllParents
,stripDir ,stripDir
-- * Path IO helpers
,withAbsPath
,withRelPath
,withFnPath
-- * ByteString/Word8 constants -- * ByteString/Word8 constants
,nullByte ,nullByte
,pathDot ,pathDot
@ -229,11 +233,6 @@ fromRel = toFilePath
normalize :: Path t -> Path t normalize :: Path t -> Path t
normalize (MkPath l) = MkPath $ normalise l normalize (MkPath l) = MkPath $ normalise l
-- | May fail on `realpath`.
canonicalizePath :: Path Abs -> IO (Path Abs)
canonicalizePath (MkPath l) = do
nl <- realpath l
return $ MkPath nl
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Path Operations -- Path Operations
@ -353,6 +352,29 @@ basename (MkPath l)
rl = last . splitPath . dropTrailingPathSeparator $ l rl = last . splitPath . dropTrailingPathSeparator $ l
--------------------------------------------------------------------------------
-- Path IO helpers
-- | May fail on `realpath`.
canonicalizePath :: Path Abs -> IO (Path Abs)
canonicalizePath (MkPath l) = do
nl <- realpath l
return $ MkPath nl
withAbsPath :: Path Abs -> (ByteString -> IO a) -> IO a
withAbsPath (MkPath p) action = action p
withRelPath :: Path Rel -> (ByteString -> IO a) -> IO a
withRelPath (MkPath p) action = action p
withFnPath :: Path Fn -> (ByteString -> IO a) -> IO a
withFnPath (MkPath p) action = action p
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- ByteString Query functions -- ByteString Query functions