Commit 705fa21d authored by Matthew Pickering's avatar Matthew Pickering Committed by Marge Bot

Hadrian: Make makeRelativeNoSysLink total

makeRelativeNoSysLink would previously crash for no reason if the first
argument as `./` due to the call to `head`. This refactoring keeps the
behaviour the same but doesn't crash in this corner case.
parent 61264556
......@@ -166,14 +166,15 @@ makeRelativeNoSysLink a b
-- Use removePrefix to get the relative paths relative to a new
-- base directory as high in the directory tree as possible.
(baseToA, baseToB) = removePrefix aRelSplit bRelSplit
aToBase = if isDirUp (head baseToA)
-- if baseToA contains any '..' then there is no way to get
-- a path from a to the base directory.
-- E.g. if baseToA == "../u/v"
-- then aToBase == "../../<UnknownDir>"
then error $ "Impossible to find relatieve path from "
aToBase = case baseToA of
(p: _) | isDirUp p ->
-- if baseToA contains any '..' then there is no way to get
-- a path from a to the base directory.
-- E.g. if baseToA == "../u/v"
-- then aToBase == "../../<UnknownDir>"
error $ "Impossible to find relatieve path from "
++ a ++ " to " ++ b
else".." <$ baseToA
_ -> ".." <$ baseToA
aToB = aToBase ++ baseToB
-- removePrefix "pre123" "prefix456" == ("123", "fix456")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment