From 45b515d1db98e795b5aba58e0867739bbc582955 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 17 Apr 2016 18:09:50 +0200 Subject: [PATCH] Add withAbsPath/withRelPath/withFnPath --- src/HPath.hs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/HPath.hs b/src/HPath.hs index acad088..1636652 100644 --- a/src/HPath.hs +++ b/src/HPath.hs @@ -43,6 +43,10 @@ module HPath ,isParentOf ,getAllParents ,stripDir + -- * Path IO helpers + ,withAbsPath + ,withRelPath + ,withFnPath -- * ByteString/Word8 constants ,nullByte ,pathDot @@ -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 @@ -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