Skip to content

Commit

Permalink
destroy: use dvc_object's remove() instead of shutil.rmtree
Browse files Browse the repository at this point in the history
`dvc_objects.fs.utils.remove()` works for readonly files too.
  • Loading branch information
skshetry committed Dec 25, 2024
1 parent 91f30b6 commit acd168e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/datachain/cache.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import shutil
from collections.abc import Iterator
from contextlib import contextmanager
from tempfile import mkdtemp
from typing import TYPE_CHECKING, Optional

from dvc_data.hashfile.db.local import LocalHashFileDB
from dvc_objects.fs.local import LocalFileSystem
from dvc_objects.fs.utils import remove
from fsspec.callbacks import Callback, TqdmCallback

from .progress import Tqdm
Expand Down Expand Up @@ -117,7 +117,7 @@ def clear(self):

def destroy(self):
# `clear` leaves the prefix directory structure intact.
shutil.rmtree(self.cache_dir)
remove(self.cache_dir)

Check warning on line 120 in src/datachain/cache.py

View check run for this annotation

Codecov / codecov/patch

src/datachain/cache.py#L120

Added line #L120 was not covered by tests

def get_total_size(self) -> int:
total = 0
Expand Down
3 changes: 2 additions & 1 deletion src/datachain/lib/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,11 @@ async def _prefetch(self, catalog=None, download_cb=None) -> bool:

client = catalog.get_client(self.source)
if client.protocol == HfClient.protocol:
self._set_stream(catalog, self._caching_enabled, download_cb=download_cb)
return False

Check warning on line 282 in src/datachain/lib/file.py

View check run for this annotation

Codecov / codecov/patch

src/datachain/lib/file.py#L282

Added line #L282 was not covered by tests

download_cb = download_cb or self._download_cb
await client._download(self, callback=download_cb)
# remove callback
self._set_stream(catalog, caching_enabled=True)
return True

Expand Down

0 comments on commit acd168e

Please sign in to comment.