Skip to content

Commit

Permalink
util: explicit isdir arg from set_log_perms
Browse files Browse the repository at this point in the history
target already exists, we should just inspect target and find if it is a
directory or not.
  • Loading branch information
dbungert committed Oct 4, 2023
1 parent ddc11d8 commit 4a4e8ba
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion subiquity/server/controllers/shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions subiquitycore/file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions subiquitycore/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
Expand Down

0 comments on commit 4a4e8ba

Please sign in to comment.