From f51156705d0b801226b6e431376dea5091870410 Mon Sep 17 00:00:00 2001 From: Bartowski Date: Wed, 13 Dec 2023 16:08:21 -0500 Subject: [PATCH] Allow symlinked folder within root directory (#4863) --- modules/utils.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/utils.py b/modules/utils.py index c1d0fb46..9f9ba0b7 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -21,16 +21,17 @@ def save_file(fname, contents): return root_folder = Path(__file__).resolve().parent.parent - abs_path = Path(fname).resolve() - rel_path = abs_path.relative_to(root_folder) + abs_path_str = os.path.abspath(fname) + rel_path_str = os.path.relpath(abs_path_str, root_folder) + rel_path = Path(rel_path_str) if rel_path.parts[0] == '..': logger.error(f'Invalid file path: {fname}') return - with open(abs_path, 'w', encoding='utf-8') as f: + with open(abs_path_str, 'w', encoding='utf-8') as f: f.write(contents) - logger.info(f'Saved {abs_path}.') + logger.info(f'Saved {abs_path_str}.') def delete_file(fname): @@ -39,8 +40,9 @@ def delete_file(fname): return root_folder = Path(__file__).resolve().parent.parent - abs_path = Path(fname).resolve() - rel_path = abs_path.relative_to(root_folder) + abs_path_str = os.path.abspath(fname) + rel_path_str = os.path.relpath(abs_path_str, root_folder) + rel_path = Path(rel_path_str) if rel_path.parts[0] == '..': logger.error(f'Invalid file path: {fname}') return