Ensure filename are store relative to project directory
This commit is contained in:
@@ -238,4 +238,32 @@ function common.normalize_path(filename)
|
||||
end
|
||||
|
||||
|
||||
local function split_on_slash(s, sep_pattern)
|
||||
local t = {}
|
||||
for fragment in string.gmatch(s, "([^/\\]+)") do
|
||||
t[#t + 1] = fragment
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
|
||||
function common.relative_path(ref_dir, dir)
|
||||
local ref_ls = split_on_slash(ref_dir)
|
||||
local dir_ls = split_on_slash(dir)
|
||||
local i = 1
|
||||
while i <= #ref_ls do
|
||||
if dir_ls[i] ~= ref_ls[i] then
|
||||
break
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
local ups = ""
|
||||
for k = i, #ref_ls do
|
||||
ups = ups .. "../"
|
||||
end
|
||||
local rel_path = ups .. table.concat(dir_ls, "/", i)
|
||||
return rel_path ~= "" and rel_path or "."
|
||||
end
|
||||
|
||||
|
||||
return common
|
||||
|
||||
Reference in New Issue
Block a user