bliss

KISS in Lua
git clone git://bvnf.space/bliss.git
Log | Files | Refs | README | LICENSE

commit 39e11097112820eb2b8e42239545e9b28ecca056
parent 4b05798e5b73f222a11f6ef4d24b8f2e6a0be855
Author: phoebos <ben@bvnf.space>
Date:   Mon, 11 Nov 2024 22:09:47 +0000

install: move file iteration to function

Diffstat:
Mbliss/install.lua | 72+++++++++++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 41 insertions(+), 31 deletions(-)

diff --git a/bliss/install.lua b/bliss/install.lua @@ -55,45 +55,55 @@ local function install(env, arg) for k,v in ipairs(tar_manifest) do tar_manifest[k] = v[1] end table.sort(tar_manifest) - -- TODO: diff manifests, remove old files, verify new files - -- PWD must contain the files - for _, file in ipairs(tar_manifest) do - local _file = env.ROOT .. file - - if file:sub(-1) == "/" then - -- Directory - if not sys_stat.stat(_file) then - local mode = sys_stat.stat("./"..file).st_mode - local c,msg = sys_stat.mkdir(_file, mode) - if not c then utils.die("mkdir "..msg) end - end - else - if file:match("^/etc/") then - -- TODO: compare checksums - warn(pkgname, "saving "..file.." as "..file..".new") - _file = _file .. ".new" - end - - local dirname = libgen.dirname(_file) - local sb = sys_stat.stat(_file) - if sb and sys_stat.S_ISLNK(sb.st_mode) ~= 0 then - if not utils.run_quiet("cp", {"-fP", "./"..file, dirname .. "/."}) then os.exit(false) end + local function iterate_files(env, tar_manifest, pkgname) + for _, file in ipairs(tar_manifest) do + local _file = env.ROOT .. file + + if file:sub(-1) == "/" then + -- Directory + if not sys_stat.stat(_file) then + local mode = sys_stat.stat("./"..file).st_mode + local c,msg = sys_stat.mkdir(_file, mode) + if not c then utils.die("mkdir "..msg) end + end else - local _tmp_file = dirname.."/__bliss-tmp-"..pkgname.."-"..libgen.basename(file).."-"..env.PID - - if not utils.run_quiet("cp", {"-fP", "./"..file, _tmp_file}) or - not utils.run_quiet("mv", {"-f", _tmp_file, _file}) then - -- run pkg_clean - getmetatable(env.atexit).__gc() + if file:match("^/etc/") then + -- TODO: compare checksums + warn(pkgname, "saving "..file.." as "..file..".new") + _file = _file .. ".new" + end - utils.log(pkgname, "Failed to install package", "ERROR") - utils.die(pkgname, "Filesystem now dirty, manual repair needed.") + local dirname = libgen.dirname(_file) + local sb = sys_stat.stat(_file) + if sb and sys_stat.S_ISLNK(sb.st_mode) ~= 0 then + if not utils.run_quiet("cp", {"-fP", "./"..file, dirname .. "/."}) then os.exit(false) end + else + local _tmp_file = dirname.."/__bliss-tmp-"..pkgname.."-"..libgen.basename(file).."-"..env.PID + + if not utils.run_quiet("cp", {"-fP", "./"..file, _tmp_file}) or + not utils.run_quiet("mv", {"-f", _tmp_file, _file}) then + -- run pkg_clean + --getmetatable(env.atexit).__gc() + env.atexit() + + utils.log(pkgname, "Failed to install package", "ERROR") + utils.die(pkgname, "Filesystem now dirty, manual repair needed.") + end end end end end + -- TODO: diff manifests, remove old files, verify new files + --[[ + eg. + if isinstalled(pkgname) then + diff, remove + end + --]] + iterate_files(env, tar_manifest, pkgname) + utils.trap_on(env) utils.log(pkgname, "Installed successfully") end