From 38c66f623d9b516ed5d59dedede36492dfcde414 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Wed, 20 Dec 2023 22:36:24 +0200 Subject: [PATCH] index: push: make sure cache files exist --- src/dvc_data/index/push.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/dvc_data/index/push.py b/src/dvc_data/index/push.py index b346e730..d84e2db2 100644 --- a/src/dvc_data/index/push.py +++ b/src/dvc_data/index/push.py @@ -10,7 +10,7 @@ from .build import build from .checkout import apply, compare from .fetch import _log_missing -from .index import ObjectStorage +from .index import DataIndex, ObjectStorage if TYPE_CHECKING: from dvc_objects.fs import FileSystem @@ -44,6 +44,22 @@ def _onerror(cache, data, failed_keys, src_path, dest_path, exc): ) +def _filter_missing(index): + ret = DataIndex() + ret.storage_map = index.storage_map + + for _, entry in index.items(): + try: + cache_fs, cache_path = index.storage_map.get_cache(entry) + except ValueError: + continue + + if cache_fs.exists(cache_path): + ret.add(entry) + + return ret + + def push( idxs, callback: "Callback" = DEFAULT_CALLBACK, @@ -83,9 +99,11 @@ def push( failed += len(result.failed) else: old = build(data.path, data.fs) + + existing_fs_index = _filter_missing(fs_index) diff = compare( old, - fs_index, + existing_fs_index, meta_only=True, meta_cmp_key=partial(_meta_checksum, data.fs), )