Skip to content

Commit

Permalink
feat: simplify path construction logic
Browse files Browse the repository at this point in the history
Simplies logic to just use nearest parent as the base instead of
traversing downwards. This reduces some redundancy, however fixes a bug
with repeated components in the constructed path and also improves
performance by skipping a loop altogether.

Also fixes recursive extraction tests failing `pandoc_soft_links.zip`.
  • Loading branch information
CompeyDev committed Feb 13, 2025
1 parent 54d46ff commit 6182e65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 10 additions & 5 deletions lib/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,19 @@ function ZipEntry.isSymlink(self: ZipEntry): boolean
end

function ZipEntry.getPath(self: ZipEntry): string
local path = self.name
local current = self.parent
if self.name == "/" then
return "/"
end

-- Get just the entry name without the path
local name = string.match(self.name, "([^/]+)/?$") or self.name

while current and current.name ~= "/" do
path = current.name .. path
current = current.parent
if not self.parent or self.parent.name == "/" then
return self.name
end

-- Combine parent path with entry name
local path = string.gsub(self.parent:getPath() .. name, "//+", "/")
return path
end

Expand Down
1 change: 0 additions & 1 deletion tests/extract.luau
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ local FALLIBLES = {
"invalid_offset2.zip",
"chinese.zip", -- Contains non local specific encoding which can't be parsed without OS APIs
"non_utf8.zip", -- FIXME: Lune breaks for non utf8 data in process stdout
"pandoc_soft_links.zip", -- Soft links are tested separately in edge_cases
}

return function(test: typeof(frktest.test))
Expand Down

0 comments on commit 6182e65

Please sign in to comment.