From 74451f4977ed4ab79f1ca7e2f6023f88cd9d5f49 Mon Sep 17 00:00:00 2001 From: onefang Date: Sat, 28 Dec 2019 03:49:40 +1000 Subject: Refactor the executers into an actual class type thingy. --- apt-panopticommon.lua | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ apt-panopticon.lua | 5 +++-- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/apt-panopticommon.lua b/apt-panopticommon.lua index c9194fa..a19f1e3 100644 --- a/apt-panopticommon.lua +++ b/apt-panopticommon.lua @@ -450,6 +450,65 @@ APT.fork = function(s) os.execute(s .. " &") end + +APT.exe = function(c) + local exe = {status = 0, result = ''} + exe.cmd = c .. ' ' + exe.log = false + + function exe:log() + self.log = true + return self + end + function exe:Nice(c) + self.cmd = self.cmd .. 'ionice -c3 nice -n 19 ' .. c .. ' ' + return self + end + function exe:And(c) + if nil == c then c = '' else c = ' ' .. c end + self.cmd = self.cmd .. '&&' .. c .. ' ' + return self + end + function exe:Or(c) + if nil == c then c = '' end + self.cmd = self.cmd .. '|| ' .. c .. ' ' + return self + end + function exe:noErr() + self.cmd = self.cmd .. '2>/dev/null ' + return self + end + function exe:wait(w) + self.cmd = self.cmd .. '&& touch ' .. w .. ' ' + return self + end + function exe:Do() + if self.log then D(" executing -   " .. self.cmd .. "") end + --[[ Damn os.execute() + Lua 5.1 says it returns "a status code, which is system-dependent" + Lua 5.2 says it returns true/nil, "exit"/"signal", the status code. + I'm getting 7168 or 0. No idea what the fuck that is. + local ok, rslt, status = os.execute(s) + ]] + local f = io.popen(self.cmd .. ' ; echo "$?"', 'r') + -- The last line will be the command's returned status, collect everything else in result. + for l in f:lines() do + self.result = self.result .. self.status .. "\n" + self.status = l + end + self.status = tonumber(self.status) + return self + end + function exe:fork() + self.cmd = '{ ' .. self.cmd .. '; } &' + if self.log then D(" forking -   " .. self.cmd .. "") end + os.execute(self.cmd) + return self + end + return exe +end + + APT.checkExes = function (exe) local count = io.popen('ps x | grep "' .. exe .. '" | grep -v " grep " | grep -v "flock -n apt-panopticon.lock " | wc -l'):read("*l") D(count .. " " .. exe .. " commands still running.") diff --git a/apt-panopticon.lua b/apt-panopticon.lua index e54e553..a97a974 100755 --- a/apt-panopticon.lua +++ b/apt-panopticon.lua @@ -1065,8 +1065,9 @@ else local adt = fadt:read('*l') fadt:close() if (nil ~= adt) and APT.checkFile(adt) then - os.execute('{ mkdir -p ' .. adt:sub(1, 18) .. ' && ionice -c3 nice -n 19' .. - ' tar -c --xz ' .. adt .. ' -f ' .. adt:sub(1, 18) .. '/' .. adt .. '.tar.xz && rm -fr ' .. adt .. ' 2>/dev/null; } &') + APT.exe('mkdir -p ' .. adt:sub(1, 18)) + :And():Nice('tar -c --xz ' .. adt .. ' -f ' .. adt:sub(1, 18) .. '/' .. adt .. '.tar.xz') + :And('rm -fr ' .. adt):noErr():fork() end local dt = os.date('!%F-%H-%M') local fodt = io.popen('TZ="GMT" date -r results/stamp +%F-%H-%M 2>/dev/null', 'r') -- cgit v1.1