Add withAbsPath/withRelPath/withFnPath
This commit is contained in:
parent
a5360f29a3
commit
45b515d1db
32
src/HPath.hs
32
src/HPath.hs
@ -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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user