Skip to content

Commit

Permalink
fix: improve reset to properly delete storage dir and jobs superdir i…
Browse files Browse the repository at this point in the history
…f not empty
  • Loading branch information
synchon committed Apr 15, 2024
1 parent 08ac0d9 commit b295207
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions junifer/api/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Synchon Mandal <[email protected]>
# License: AGPL

import os
import shutil
import typing
from pathlib import Path
Expand Down Expand Up @@ -339,12 +340,12 @@ def reset(config: Dict) -> None:
storage = config["storage"]
storage_uri = Path(storage["uri"])
logger.info(f"Deleting {storage_uri.resolve()!s}")
# Delete storage; will be str
# Delete storage
if storage_uri.exists():
# Delete files in the directory
for file in storage_uri.iterdir():
# Delete files in the job storage directory
for file in storage_uri.parent.iterdir():
file.unlink(missing_ok=True)
# Remove directory
# Remove job storage directory
storage_uri.parent.rmdir()

# Fetch job name (if present)
Expand All @@ -359,5 +360,6 @@ def reset(config: Dict) -> None:
if job_dir.exists():
# Remove files and directories
shutil.rmtree(job_dir)
# Remove directory
job_dir.parent.rmdir()
# Remove parent directory (if empty)
if not next(os.scandir(job_dir.parent), None):
job_dir.parent.rmdir()

0 comments on commit b295207

Please sign in to comment.