Skip to content

Commit

Permalink
[core] Ignore error of failed deletion of non-empty directory
Browse files Browse the repository at this point in the history
  • Loading branch information
aschuh-hf committed Sep 1, 2023
1 parent 9cbcb02 commit 0ba0e88
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/deepali/core/pathlib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
r"""File path utility functions."""

from errno import ENOTEMPTY
import os
from os import rmdir
from pathlib import Path
Expand Down Expand Up @@ -79,7 +80,12 @@ def delete(path: PathStr, non_empty: bool = True) -> bool:
if non_empty:
rmtree(path)
else:
rmdir(path)
try:
rmdir(path)
except OSError as error:
if error.errno == ENOTEMPTY:
return False
raise
else:
try:
path.unlink()
Expand Down

0 comments on commit 0ba0e88

Please sign in to comment.