From 4a4e8ba8863401404a132784dfd66ce04822984b Mon Sep 17 00:00:00 2001 From: Dan Bungert Date: Tue, 3 Oct 2023 18:56:07 -0600 Subject: [PATCH] util: explicit isdir arg from set_log_perms target already exists, we should just inspect target and find if it is a directory or not. --- subiquity/server/controllers/shutdown.py | 2 +- subiquitycore/file_util.py | 6 ++---- subiquitycore/log.py | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/subiquity/server/controllers/shutdown.py b/subiquity/server/controllers/shutdown.py index 971bbe410..503d0ce31 100644 --- a/subiquity/server/controllers/shutdown.py +++ b/subiquity/server/controllers/shutdown.py @@ -113,7 +113,7 @@ async def copy_logs_to_target(self, context): ["cp", "-aT", "/var/log/installer", target_logs] ) # Close the permissions from group writes on the target. - set_log_perms(target_logs, isdir=True, group_write=False) + set_log_perms(target_logs, group_write=False) journal_txt = os.path.join(target_logs, "installer-journal.txt") try: diff --git a/subiquitycore/file_util.py b/subiquitycore/file_util.py index 461e5396f..3e67194c9 100644 --- a/subiquitycore/file_util.py +++ b/subiquitycore/file_util.py @@ -29,9 +29,7 @@ log = logging.getLogger("subiquitycore.file_util") -def set_log_perms( - target, *, isdir=True, group_write=False, mode=None, group=_DEF_GROUP -): +def set_log_perms(target, *, group_write=False, mode=None, group=_DEF_GROUP): if os.getuid() != 0: log.warning( "set_log_perms: running as non-root - not adjusting" @@ -41,7 +39,7 @@ def set_log_perms( return if mode is None: mode = _DEF_PERMS_FILE - if isdir: + if os.path.isdir(target): mode |= 0o110 if group_write: mode |= 0o020 diff --git a/subiquitycore/log.py b/subiquitycore/log.py index f04f2d1eb..36a54f978 100644 --- a/subiquitycore/log.py +++ b/subiquitycore/log.py @@ -23,7 +23,7 @@ def setup_logger(dir, base="subiquity"): os.makedirs(dir, exist_ok=True) # Create the log directory in such a way that users in the group may # write to this directory in the installation environment. - set_log_perms(dir, isdir=True, group_write=True) + set_log_perms(dir, group_write=True) logger = logging.getLogger("") logger.setLevel(logging.DEBUG) @@ -34,7 +34,7 @@ def setup_logger(dir, base="subiquity"): nopid_file = os.path.join(dir, "{}-{}.log".format(base, level)) logfile = "{}.{}".format(nopid_file, os.getpid()) handler = logging.FileHandler(logfile) - set_log_perms(logfile, isdir=False, group_write=False) + set_log_perms(logfile, group_write=False) # os.symlink cannot replace an existing file or symlink so create # it and then rename it over. tmplink = logfile + ".link"