Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

files deleting fixed #22

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions deker_local_adapters/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,26 @@ class LocalAdapterMixin(object):
logger: Logger
executor: ThreadPoolExecutor

def _delete(self, file: Path) -> None:
def _delete(self, symlink: Path) -> None:
"""Delete symlink and realpath files from disk.

:param file: path to the file
:param symlink: path to the symlink file
"""
try:
if file.exists():
os.remove(file)
if file.parent.exists():
for folder in file.parents:
subs = os.listdir(folder)
if subs or any(str(folder).endswith(directory) for directory in self.dirs):
break
if folder.exists():
os.rmdir(folder)
data = symlink.readlink()
if data.exists():
os.remove(data)

symlink.unlink(missing_ok=True)

for file in (data, symlink):
if file.parent.exists():
for folder in file.parents:
subs = os.listdir(folder)
if subs or any(str(folder).endswith(directory) for directory in self.dirs):
break
if folder.exists():
os.rmdir(folder)
except FileNotFoundError:
pass

Expand All @@ -79,9 +84,7 @@ def delete(self, array: Union[Array, VArray]) -> None:
try:
paths = get_paths(array, self.collection_path)
filename = array.id + self.file_ext
files = (paths.symlink / filename, paths.main / filename)
for file in files:
self._delete(file)
self._delete(paths.symlink / filename)

except Exception as e:
self.logger.exception(e)
Expand Down
Loading