From 7e77e6335bab772c4be1b3f0594113d09cd4a366 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Thu, 23 Sep 2021 03:01:09 +0200 Subject: handle all maps in entire repositories (+ checking that paths don't run outside of respositories) --- lib/Paths.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lib/Paths.hs') 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 -- cgit v1.2.3