Skip to content

Commit

Permalink
Add withAbsPath/withRelPath/withFnPath
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Apr 17, 2016
1 parent a5360f2 commit 45b515d
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/HPath.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ module HPath
,isParentOf
,getAllParents
,stripDir
-- * Path IO helpers
,withAbsPath
,withRelPath
,withFnPath
-- * ByteString/Word8 constants
,nullByte
,pathDot
Expand Down Expand Up @@ -229,11 +233,6 @@ fromRel = toFilePath
normalize :: Path t -> Path t
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
Expand Down Expand Up @@ -353,6 +352,29 @@ basename (MkPath 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

Expand Down

0 comments on commit 45b515d

Please sign in to comment.