aboutsummaryrefslogtreecommitdiff
path: root/src/lib/path.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/path.lua')
-rw-r--r--src/lib/path.lua13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/lib/path.lua b/src/lib/path.lua
index a0be1e5..925f017 100644
--- a/src/lib/path.lua
+++ b/src/lib/path.lua
@@ -8,6 +8,7 @@ function Path:new(p)
p = p:gsub("/$", "")
p = p:gsub("^%./", "")
p = p:gsub("/[^/]+/%.%.", "")
+ p = p:gsub("^[^/]+/%.%./", "")
local path = {
segments = p:split('/'),
@@ -126,6 +127,18 @@ function Path:remove(opts)
pipe:close()
end
+function Path:is_parent_of(child)
+ return tostring(child):starts_with(tostring(self))
+end
+
+function Path:relative_to_parent(path)
+ if not path:is_parent_of(self) then
+ return nil
+ end
+
+ return Path:new(tostring(self):sub(#tostring(path) + 2))
+end
+
return {
tests = {
function()