Skip to content

Commit

Permalink
Merge pull request #332 from juaml/fix/reset
Browse files Browse the repository at this point in the history
[BUG]: `junifer reset` fails as it tries to delete `junifer_jobs` directory
  • Loading branch information
synchon authored Apr 30, 2024
2 parents 8f96159 + b7f6b89 commit 0646a6f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/changes/newsfragments/332.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``junifer reset`` to properly delete storage directory and handle ``junifer_jobs`` deletion if not empty by `Synchon Mandal`_
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 <s.mandal@fz-juelich.de>
# 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,8 +360,9 @@ 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()

Check failure on line 365 in junifer/api/functions.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W291)

junifer/api/functions.py:365:39: W291 Trailing whitespace


def list_elements(
Expand Down

0 comments on commit 0646a6f

Please # to comment.