From 5505421f6404e73028d25211cdd113bd7a23e2e9 Mon Sep 17 00:00:00 2001 From: cryi Date: Sun, 7 Jan 2024 00:12:35 +0100 Subject: [PATCH] support contentOnly for zip compression when targeting directory --- config.hjson | 2 +- lib/eli/zip.lua | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/config.hjson b/config.hjson index 17fd376..07c6de5 100644 --- a/config.hjson +++ b/config.hjson @@ -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 diff --git a/lib/eli/zip.lua b/lib/eli/zip.lua index 1bdeea8..e1d6b8d 100644 --- a/lib/eli/zip.lua +++ b/lib/eli/zip.lua @@ -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)) @@ -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) @@ -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' --- @@ -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)