From c5f6c4b71263ebfc2a6d840847328b672fd8d5c2 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 23 Mar 2021 11:28:52 +0100 Subject: Partially corrects for #116. We still don't detect if we're running as root (need to investigate if we need to run as root first). But this should at least hot-swap the log-file to the current working directory and place the logfile there. --- archinstall/lib/output.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'archinstall/lib/output.py') diff --git a/archinstall/lib/output.py b/archinstall/lib/output.py index 0e0a295b..18cbefe0 100644 --- a/archinstall/lib/output.py +++ b/archinstall/lib/output.py @@ -96,7 +96,16 @@ def log(*args, **kwargs): if (filename := storage.get('LOG_FILE', None)): absolute_logfile = os.path.join(storage.get('LOG_PATH', './'), filename) if not os.path.isfile(absolute_logfile): - os.makedirs(os.path.dirname(absolute_logfile)) + try: + os.makedirs(os.path.dirname(absolute_logfile)) + except PermissionError: + # Fallback to creating the log file in the current folder + log(f"Not enough permission to place log file at {absolute_logfile}, creating it in {Path('./').absolute()} instead.", fg="red") + absolute_logfile = Path('./').absolute()/filename + absolute_logfile.makedirs(exist_ok=True) + storage['LOG_PATH'] = './' + + Path(absolute_logfile).touch() # Overkill? with open(absolute_logfile, 'a') as log_file: -- cgit v1.2.3-70-g09d2 From aceb0f3e98ea1009474f24cf02fdcf3e5923bcc7 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 23 Mar 2021 11:42:12 +0100 Subject: Corrected recursion loop in log() calling log() before setting the new path for the log file on errors. --- archinstall/lib/output.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'archinstall/lib/output.py') diff --git a/archinstall/lib/output.py b/archinstall/lib/output.py index 18cbefe0..537fb695 100644 --- a/archinstall/lib/output.py +++ b/archinstall/lib/output.py @@ -97,14 +97,15 @@ def log(*args, **kwargs): absolute_logfile = os.path.join(storage.get('LOG_PATH', './'), filename) if not os.path.isfile(absolute_logfile): try: - os.makedirs(os.path.dirname(absolute_logfile)) + Path(absolute_logfile).parents[0].mkdir(exist_ok=True, parents=True) except PermissionError: # Fallback to creating the log file in the current folder - log(f"Not enough permission to place log file at {absolute_logfile}, creating it in {Path('./').absolute()} instead.", fg="red") + 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.makedirs(exist_ok=True) + 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? -- cgit v1.2.3-70-g09d2