mirror of
https://github.com/xpltdco/media-rip.git
synced 2026-04-03 02:53:58 -06:00
Fix purge: use full relative path for file deletion, clean empty dirs
- Bug: purge used Path(filename).name which stripped subdirectories, so files like 'jawed/Me at the zoo.webm' were never found/deleted - Fix: use output_dir / filename (preserves relative path) - Also: clean up empty parent directories after file deletion so uploader folders like 'jawed/' don't linger as empty dirs
This commit is contained in:
parent
2e87da297f
commit
723e7f4248
1 changed files with 10 additions and 1 deletions
|
|
@ -74,12 +74,21 @@ async def run_purge(
|
|||
|
||||
# Delete file from disk if it exists
|
||||
if filename:
|
||||
file_path = output_dir / Path(filename).name
|
||||
file_path = output_dir / filename
|
||||
if file_path.is_file():
|
||||
try:
|
||||
file_path.unlink()
|
||||
files_deleted += 1
|
||||
logger.debug("Purge: deleted file %s (job %s)", file_path, job_id)
|
||||
# Clean up empty parent directories up to output_dir
|
||||
parent = file_path.parent
|
||||
while parent != output_dir:
|
||||
try:
|
||||
parent.rmdir() # only removes if empty
|
||||
logger.debug("Purge: removed empty dir %s", parent)
|
||||
parent = parent.parent
|
||||
except OSError:
|
||||
break
|
||||
except OSError as e:
|
||||
logger.warning("Purge: failed to delete %s: %s", file_path, e)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue