fix file.remove_ext

This commit is contained in:
MihailRis 2026-09-20 22:01:18 +03:00
parent 60f184ae43
commit b9b17358a1
2 changed files with 6 additions and 1 deletions

View file

@ -2,6 +2,7 @@ debug.log("file extension")
asserts.equals(nil, file.ext("config:test"))
asserts.equals("cfg", file.ext("config:test.cfg"))
asserts.equals("gz", file.ext("config:test.cfg.gz"))
asserts.equals("config:test.cfg", file.remove_ext("config:test.cfg.gz"))
debug.log("check initial state")
assert(file.exists("config:"))

View file

@ -24,7 +24,11 @@ function file.parent(path)
end
function file.remove_ext(path)
return string.format("%s/%s", file.parent(path), file.stem(path))
local ext = file.ext(path)
if not ext then
return path
end
return path:sub(1, -#ext - 2)
end
function file.path(path)