diff options
Diffstat (limited to '')
-rw-r--r-- | lib/Paths.hs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/Paths.hs b/lib/Paths.hs index 4dcaa53..49c0295 100644 --- a/lib/Paths.hs +++ b/lib/Paths.hs @@ -4,10 +4,12 @@ module Paths where -import Data.Text (Text) -import qualified Data.Text as T +import Data.Text (Text) +import qualified Data.Text as T +import System.FilePath (splitPath) +import System.FilePath.Posix ((</>)) import Text.Regex.TDFA -import Util (PrettyPrint (prettyprint)) +import Util (PrettyPrint (prettyprint)) -- | a normalised path: a number of "upwards" steps, and -- a path without any . or .. in it @@ -35,6 +37,8 @@ instance PrettyPrint RelPath where prettyprint (Path up rest _) = ups <> rest where ups = T.concat $ replicate up "../" -normalise :: RelPath -> FilePath -normalise (Path 0 path _) = T.unpack path -normalize _ = error "not implemented yet" +normalise :: FilePath -> RelPath -> FilePath +normalise prefix (Path 0 path _) = prefix </> T.unpack path +normalise prefix (Path i path _) = + concat (take (length dirs - i) dirs) </> T.unpack path + where dirs = splitPath prefix |