From 2c65f0834b959a09295052359000eca007f6195d Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 15 May 2022 11:58:13 +0200 Subject: [PATCH] gluon-autoupdater: factor out default_branch() function Make the code clearer and prepare for invalid branch fixup. --- .../luasrc/lib/gluon/upgrade/500-autoupdater | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/package/gluon-autoupdater/luasrc/lib/gluon/upgrade/500-autoupdater b/package/gluon-autoupdater/luasrc/lib/gluon/upgrade/500-autoupdater index 6ccd3072..10f6197f 100755 --- a/package/gluon-autoupdater/luasrc/lib/gluon/upgrade/500-autoupdater +++ b/package/gluon-autoupdater/luasrc/lib/gluon/upgrade/500-autoupdater @@ -21,16 +21,21 @@ for name, config in pairs(site.autoupdater.branches()) do end end +local function default_branch() + local f = io.open('/lib/gluon/autoupdater/default_branch') + if f then + local ret = f:read('*line') + f:close() + return ret + end + + return site.autoupdater.branch(min_branch) +end + if not uci:get('autoupdater', 'settings') then local enabled = unistd.access('/lib/gluon/autoupdater/default_enabled') ~= nil - local branch = site.autoupdater.branch(min_branch) - local f = io.open('/lib/gluon/autoupdater/default_branch') - if f then - branch = f:read('*line') - f:close() - end - + local branch = default_branch() if not branch then enabled = false end