Skip to content

Commit

Permalink
support contentOnly for zip compression when targeting directory
Browse files Browse the repository at this point in the history
  • Loading branch information
cryi committed Jan 6, 2024
1 parent 12dce91 commit 5505421
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config.hjson
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
version: 0.32.0-dev.5
version: 0.32.0-dev.6
global_modules: false //disables global modules loading (only looks up for modules in cwd)
minify: true
compress: true
Expand Down
10 changes: 8 additions & 2 deletions lib/eli/zip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function zip.extract(source, destination, options)

-- by default we assume that mkdir is nor supported and we cannot create directories
local _targetPath = _path.file(stat.name)
if type(_transform_path) == "function" then -- if supplied transform with transform functions
if type(_transform_path) == "function" then -- if supplied transform with transform functions
_targetPath = _transform_path(stat.name:sub(il), destination)
elseif type(_mkdirp) == "function" and type(destination) == "string" then --mkdir supported we can use path as is :)
_targetPath = _path.combine(destination, stat.name:sub(il))
Expand All @@ -136,7 +136,7 @@ function zip.extract(source, destination, options)
_close_file(_f)
end
local _externalAtrributes = zipArch:get_external_attributes(i)
if _externalChmod then -- we got supplied chmod
if _externalChmod then -- we got supplied chmod
_chmod(_targetPath, _externalAtrributes)
elseif type(_externalAtrributes) == "number" then -- we use built in chmod
local _permissions = math.floor(_externalAtrributes / 2 ^ 16)
Expand Down Expand Up @@ -322,6 +322,8 @@ end
---@field preserveFullPath nil|boolean
---#DES 'CompressOptions.recurse'
---@field recurse nil|boolean
---#DES 'CompressOptions.contentOnly'
---@field contentOnly boolean? aplicable only when source is directory

---#DES 'zip.compress'
---
Expand Down Expand Up @@ -353,6 +355,10 @@ function zip.compress(source, target, options)
_skipLength = #source - #_targetName + 1
end

if options.contentOnly and fs.file_type(source) == "directory" and not options.preserveFullPath then
_skipLength = #source + 1
end

local _archive = zip.new_archive(target)
if fs.file_type(source) == "file" then
zip.add_to_archive(_archive, source:sub(_skipLength), "file", source)
Expand Down

0 comments on commit 5505421

Please sign in to comment.