Skip to content

Commit

Permalink
Refactor delete method to not remove empty directories
Browse files Browse the repository at this point in the history
  • Loading branch information
doulikecookiedough committed Dec 29, 2023
1 parent 255673e commit f704389
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/hashstore/filehashstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1857,10 +1857,12 @@ def delete(self, entity, file):

try:
os.remove(realpath)
except OSError:
pass
else:
self._remove_empty(os.path.dirname(realpath))
except OSError as err:
exception_string = (
f"FileHashStore - delete(): Unexpected {err=}, {type(err)=}"
)
logging.error(exception_string)
raise err

def _remove_empty(self, subpath):
"""Successively remove all empty folders starting with `subpath` and
Expand Down

0 comments on commit f704389

Please sign in to comment.