diff --git a/config.hjson b/config.hjson index 4dfdc13..794ea98 100644 --- a/config.hjson +++ b/config.hjson @@ -1,5 +1,5 @@ { - version: 0.34.4 + version: 0.34.5 global_modules: false //disables global modules loading (only looks up for modules in cwd) minify: true compress: true diff --git a/lib/eli/fs.lua b/lib/eli/fs.lua index 31928c6..11d0674 100644 --- a/lib/eli/fs.lua +++ b/lib/eli/fs.lua @@ -71,6 +71,8 @@ function fs.copy_file(src, dst, options) "Invalid type of destination! (Has to be string or file*)") options = _util.merge_tables({ binaryMode = true }, options, true) + local file_info = fs.file_info(src) + local permissions = (file_info or {}).permissions or "rw-r--r--" ---@type file*, file* local srcf, dstf if type(src) == "string" then @@ -96,6 +98,9 @@ function fs.copy_file(src, dst, options) end if type(src) == "string" then srcf:close() end if type(dst) == "string" then dstf:close() end + if type(dst) == "string" then + fs.chmod(dst, permissions) + end end ---@class FsCopyoptions @@ -129,7 +134,9 @@ function fs.copy(src, dst, options) if fs.exists(dstFile) and fs.file_type(dstFile) ~= "directory" then error"Cannot copy directory to file!" end + local file_info = fs.file_info(srcFile) or {} fs.mkdirp(dstFile) + fs.chmod(dstFile, file_info.permissions) elseif not fs.exists(dstFile) or options.overwrite then fs.mkdirp(_eliPath.dir(dstFile)) fs.copy_file(_eliPath.combine(src, srcFile) --[[@as string]], dstFile, options) diff --git a/lib/init.lua b/lib/init.lua index 68596db..183ee66 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -1,5 +1,5 @@ -ELI_LIB_VERSION = '0.34.3' -ELI_VERSION = '0.34.3' +ELI_LIB_VERSION = '0.34.5' +ELI_VERSION = '0.34.5' do local path = require"eli.path" local _eos = require"eli.os" diff --git a/lib/tests/assets/test.bin b/lib/tests/assets/test.bin new file mode 100755 index 0000000..e69de29 diff --git a/lib/tests/fs.lua b/lib/tests/fs.lua index 28eeac1..017dc15 100644 --- a/lib/tests/fs.lua +++ b/lib/tests/fs.lua @@ -23,7 +23,7 @@ test["copy file (path)"] = function () local _ok, _hash = eliFs.safe_hash_file("assets/test.file", { type = "sha256", hex = true }) test.assert(_ok, _hash) local _ok, _hash2 = - eliFs.safe_hash_file("tmp/test.file", { type = "sha256", hex = true }) + eliFs.safe_hash_file("tmp/test.file", { type = "sha256", hex = true }) test.assert(_ok, _hash) test.assert(_hash == _hash2, "hashes do not match (" .. tostring(_hash) .. "<>" .. tostring(_hash2) .. ")") end @@ -65,6 +65,15 @@ test["copy file (mixed)"] = function () test.assert(_hash == _hash2, "hashes do not match (" .. tostring(_hash) .. "<>" .. tostring(_hash2) .. ")") end +test["copy file (permissions)"] = function () + local _ok, _error = eliFs.safe_copy_file("assets/test.bin", + "tmp/test.bin") + test.assert(_ok, _error) + local info = eliFs.file_info"assets/test.bin" + local info2 = eliFs.file_info"tmp/test.bin" + test.assert(info.permissions == info2.permissions, "permissions do not match") +end + test["copy (file)"] = function () local _ok, _error = eliFs.safe_copy("assets/test.file", "tmp/test.file") @@ -72,7 +81,7 @@ test["copy (file)"] = function () local _ok, _hash = eliFs.safe_hash_file("assets/test.file", { type = "sha256", hex = true }) test.assert(_ok, _hash) local _ok, _hash2 = - eliFs.safe_hash_file("tmp/test.file", { type = "sha256", hex = true }) + eliFs.safe_hash_file("tmp/test.file", { type = "sha256", hex = true }) test.assert(_ok, _hash) test.assert(_hash == _hash2, "hashes do not match (" .. tostring(_hash) .. "<>" .. tostring(_hash2) .. ")") end @@ -94,7 +103,7 @@ test["copy (directory)"] = function () test.assert(_ok, _hash) local destFilePath = eliPath.combine(DEST_DIR, filePath) local _ok, _hash2 = - eliFs.safe_hash_file(destFilePath, { type = "sha256", hex = true }) + eliFs.safe_hash_file(destFilePath, { type = "sha256", hex = true }) test.assert(_ok, _hash) test.assert(_hash == _hash2, "hashes do not match (" .. tostring(_hash) .. "<>" .. tostring(_hash2) .. ")") ::continue:: @@ -119,7 +128,7 @@ test["copy (directory - overwrite)"] = function () test.assert(_ok, _hash) local destFilePath = eliPath.combine(DEST_DIR, filePath) local _ok, _hash2 = - eliFs.safe_hash_file(destFilePath, { type = "sha256", hex = true }) + eliFs.safe_hash_file(destFilePath, { type = "sha256", hex = true }) test.assert(_ok, _hash) test.assert(_hash == _hash2, "hashes do not match (" .. tostring(_hash) .. "<>" .. tostring(_hash2) .. ")") ::continue:: @@ -136,7 +145,7 @@ test["copy (directory - overwrite)"] = function () test.assert(_ok, _hash) local destFilePath = eliPath.combine(DEST_DIR, filePath) local _ok, _hash2 = - eliFs.safe_hash_file(destFilePath, { type = "sha256", hex = true }) + eliFs.safe_hash_file(destFilePath, { type = "sha256", hex = true }) test.assert(_ok, _hash) test.assert(_hash == _hash2, "hashes do not match (" .. tostring(_hash) .. "<>" .. tostring(_hash2) .. ")") ::continue:: @@ -154,7 +163,7 @@ test["copy (directory - overwrite)"] = function () test.assert(_ok, _hash) local destFilePath = eliPath.combine(DEST_DIR, filePath) local _ok, _hash2 = - eliFs.safe_hash_file(destFilePath, { type = "sha256", hex = true }) + eliFs.safe_hash_file(destFilePath, { type = "sha256", hex = true }) test.assert(_ok, _hash) test.assert(_hash == _hash2, "hashes do not match (" .. tostring(_hash) .. "<>" .. tostring(_hash2) .. ")") ::continue:: @@ -401,9 +410,9 @@ end local function _external_lock(file) local _cmd = (os.getenv"QEMU" or "") .. - " " .. arg[-1] .. " -e \"x, err = fs.lock_file('" .. file .. "','w'); " .. - "if etype(x) == 'ELI_FILE_LOCK' then os.exit(0); end; notAvailable = tostring(err):match('Resource temporarily unavailable') or tostring(err):match('locked a portion of the file'); " .. - "exitCode = notAvailable and 11 or 12; os.exit(exitCode)\"" + " " .. arg[-1] .. " -e \"x, err = fs.lock_file('" .. file .. "','w'); " .. + "if etype(x) == 'ELI_FILE_LOCK' then os.exit(0); end; notAvailable = tostring(err):match('Resource temporarily unavailable') or tostring(err):match('locked a portion of the file'); " .. + "exitCode = notAvailable and 11 or 12; os.exit(exitCode)\"" local _ok, _, _code = os.execute(_cmd) return _ok, _code end