Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow symlinked folder within root directory #4863

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down