-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve reset to properly delete storage dir and jobs superdir i…
…f not empty
- Loading branch information
Showing
1 changed file
with
8 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
# Synchon Mandal <[email protected]> | ||
# License: AGPL | ||
|
||
import os | ||
import shutil | ||
import typing | ||
from pathlib import Path | ||
|
@@ -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) | ||
|
@@ -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() |