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.
This commit is contained in:
Dan Bungert 2023-10-03 18:56:07 -06:00
parent ddc11d8687
commit 4a4e8ba886
3 changed files with 5 additions and 7 deletions

View File

@ -113,7 +113,7 @@ class ShutdownController(SubiquityController):
["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:

View File

@ -29,9 +29,7 @@ _DEF_GROUP = "adm"
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

View File

@ -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"