Merge pull request #592 from tcely/patch-6
Some checks failed
Run Django tests for TubeSync / test (3.7) (push) Has been cancelled
Run Django tests for TubeSync / test (3.8) (push) Has been cancelled
Run Django tests for TubeSync / test (3.9) (push) Has been cancelled
Run Django tests for TubeSync / containerise (push) Has been cancelled

Use Path in file_is_editable
This commit is contained in:
meeb 2024-12-22 19:06:40 +11:00 committed by GitHub
commit 904c57f603
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -100,15 +100,16 @@ def file_is_editable(filepath):
'''
allowed_paths = (
# Media item thumbnails
os.path.commonpath([os.path.abspath(str(settings.MEDIA_ROOT))]),
Path(str(settings.MEDIA_ROOT)).resolve(),
# Downloaded media files
os.path.commonpath([os.path.abspath(str(settings.DOWNLOAD_ROOT))]),
Path(str(settings.DOWNLOAD_ROOT)).resolve(),
)
filepath = os.path.abspath(str(filepath))
if not os.path.isfile(filepath):
filepath = Path(str(filepath)).resolve()
if not filepath.is_file():
return False
for allowed_path in allowed_paths:
if allowed_path == os.path.commonpath([allowed_path, filepath]):
if str(allowed_path) == os.path.commonpath([allowed_path, filepath]):
return True
return False