Skip to content
Open
Show file tree
Hide file tree
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
44 changes: 26 additions & 18 deletions dvc/data_cloud.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Manages dvc remotes that user can use with push/pull/status commands."""

from collections.abc import Iterable
from contextlib import closing
from typing import TYPE_CHECKING, Optional

from dvc.config import NoRemoteError, RemoteConfigError
Expand Down Expand Up @@ -210,16 +211,19 @@ def _push(
cache = self.repo.cache.legacy
else:
cache = self.repo.cache.local
with TqdmCallback(
desc=f"Pushing to {odb.fs.unstrip_protocol(odb.path)}",
unit="file",
) as cb:
with (
closing(get_index(odb)) as index,
TqdmCallback(
desc=f"Pushing to {odb.fs.unstrip_protocol(odb.path)}",
unit="file",
) as cb,
):
return self.transfer(
cache,
odb,
objs,
jobs=jobs,
dest_index=get_index(odb),
dest_index=index,
cache_odb=cache,
validate_status=self._log_missing,
callback=cb,
Expand Down Expand Up @@ -271,16 +275,19 @@ def _pull(
cache = self.repo.cache.legacy
else:
cache = self.repo.cache.local
with TqdmCallback(
desc=f"Fetching from {odb.fs.unstrip_protocol(odb.path)}",
unit="file",
) as cb:
with (
closing(get_index(odb)) as index,
TqdmCallback(
desc=f"Fetching from {odb.fs.unstrip_protocol(odb.path)}",
unit="file",
) as cb,
):
return self.transfer(
odb,
cache,
objs,
jobs=jobs,
src_index=get_index(odb),
src_index=index,
cache_odb=cache,
verify=odb.verify,
validate_status=self._log_missing,
Expand Down Expand Up @@ -340,14 +347,15 @@ def _status(
cache = self.repo.cache.legacy
else:
cache = self.repo.cache.local
return compare_status(
cache,
odb,
objs,
jobs=jobs,
dest_index=get_index(odb),
cache_odb=cache,
)
with closing(get_index(odb)) as index:
return compare_status(
cache,
odb,
objs,
jobs=jobs,
dest_index=index,
cache_odb=cache,
)

def get_url_for(self, remote, checksum):
odb = self.get_remote_odb(remote)
Expand Down
5 changes: 3 additions & 2 deletions dvc/repo/gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def gc( # noqa: C901, PLR0912, PLR0913
not_in_remote=not_in_remote,
)

from contextlib import ExitStack
from contextlib import ExitStack, closing

from dvc.repo import Repo
from dvc_data.hashfile.db import get_index
Expand Down Expand Up @@ -148,7 +148,8 @@ def gc( # noqa: C901, PLR0912, PLR0913
assert remote_odb is not None
num_removed = ogc(remote_odb, obj_ids, jobs=jobs, dry=dry)
if num_removed:
get_index(remote_odb).clear()
with closing(get_index(remote_odb)) as index:
index.clear()
logger.info("Removed %d objects from remote.", num_removed)
else:
logger.info("No unused cache to remove from remote.")
Expand Down
Loading