Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib
diff options
context:
space:
mode:
authorAnton Hvornum <anton.feeds@gmail.com>2021-04-28 14:28:21 +0200
committerAnton Hvornum <anton.feeds@gmail.com>2021-04-28 14:28:21 +0200
commit04804e6edc13fd4cfcba898767919ae9f187842b (patch)
treede87bed17e5652be237fba4fdeae8098283fa68a /archinstall/lib
parent09cab3274911143e4230f3b3dce7b7147b13e816 (diff)
Corrected error handling for log creation.
Diffstat (limited to 'archinstall/lib')
-rw-r--r--archinstall/lib/output.py31
1 files changed, 14 insertions, 17 deletions
diff --git a/archinstall/lib/output.py b/archinstall/lib/output.py
index 6a294f40..872de3d0 100644
--- a/archinstall/lib/output.py
+++ b/archinstall/lib/output.py
@@ -103,30 +103,27 @@ def log(*args, **kwargs):
kwargs = {'fg': 'white', **kwargs}
string = stylize_output(string, **kwargs)
- # If a logfile is defined in storage,
+ # If a logfile is defined in storage,
# we use that one to output everything
if (filename := storage.get('LOG_FILE', None)):
absolute_logfile = os.path.join(storage.get('LOG_PATH', './'), filename)
- if not os.path.isfile(absolute_logfile):
- try:
- Path(absolute_logfile).parents[0].mkdir(exist_ok=True, parents=True)
- with open(absolute_logfile, 'a') as log_file:
- log_file.write("")
- except PermissionError:
- # Fallback to creating the log file in the current folder
- err_string = f"Not enough permission to place log file at {absolute_logfile}, creating it in {Path('./').absolute()/filename} instead."
- absolute_logfile = Path('./').absolute()/filename
- absolute_logfile.parents[0].mkdir(exist_ok=True)
- absolute_logfile = str(absolute_logfile)
- storage['LOG_PATH'] = './'
- log(err_string, fg="red")
-
- Path(absolute_logfile).touch() # Overkill?
+
+ try:
+ Path(absolute_logfile).parents[0].mkdir(exist_ok=True, parents=True)
+ with open(absolute_logfile, 'a') as log_file:
+ log_file.write("")
+ except PermissionError:
+ # Fallback to creating the log file in the current folder
+ err_string = f"Not enough permission to place log file at {absolute_logfile}, creating it in {Path('./').absolute()/filename} instead."
+ absolute_logfile = Path('./').absolute()/filename
+ absolute_logfile.parents[0].mkdir(exist_ok=True)
+ absolute_logfile = str(absolute_logfile)
+ storage['LOG_PATH'] = './'
+ log(err_string, fg="red")
with open(absolute_logfile, 'a') as log_file:
log_file.write(f"{orig_string}\n")
-
# If we assigned a level, try to log it to systemd's journald.
# Unless the level is higher than we've decided to output interactively.
# (Remember, log files still get *ALL* the output despite level restrictions)