summaryrefslogtreecommitdiff
path: root/lib/Paths.hs
diff options
context:
space:
mode:
authorstuebinm2021-09-23 03:01:09 +0200
committerstuebinm2021-09-23 03:01:09 +0200
commit7e77e6335bab772c4be1b3f0594113d09cd4a366 (patch)
treeaa2e45b84b4b3ec17d562fd80276a307e6e88267 /lib/Paths.hs
parent7ad5e1cd504b1d57ff3660f9eb81d2e7072ea4bf (diff)
handle all maps in entire repositories
(+ checking that paths don't run outside of respositories)
Diffstat (limited to '')
-rw-r--r--lib/Paths.hs16
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