diff --git a/setup.cfg b/setup.cfg index 74bcdde0..147a87ea 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,7 +28,7 @@ install_requires= dictdiffer>=0.8.1 pygtrie>=2.3.2 shortuuid>=0.5.0 - dvc-objects==0.16.0 + dvc-objects==0.17.0 diskcache>=5.2.1 nanotime>=0.5.2 attrs>=21.3.0 diff --git a/src/dvc_data/hashfile/gc.py b/src/dvc_data/hashfile/gc.py index 1eee197a..7de90b93 100644 --- a/src/dvc_data/hashfile/gc.py +++ b/src/dvc_data/hashfile/gc.py @@ -23,10 +23,10 @@ def _is_dir_hash(_hash): return _hash.endswith(HASH_DIR_SUFFIX) removed = False - # hashes must be sorted to ensure we always remove .dir files first - hashes = QueryingProgress(odb.all(jobs), name=odb.path) - for hash_ in sorted(hashes, key=_is_dir_hash, reverse=True): + dir_paths = [] + file_paths = [] + for hash_ in QueryingProgress(odb.all(jobs), name=odb.path): if hash_ in used_hashes: continue path = odb.oid_to_path(hash_) @@ -34,7 +34,13 @@ def _is_dir_hash(_hash): # backward compatibility # pylint: disable=protected-access odb._remove_unpacked_dir(hash_) - odb.fs.remove(path) - removed = True + dir_paths.append(path) + else: + file_paths.append(path) + + for paths in (dir_paths, file_paths): + if paths: + removed = True + odb.fs.remove(paths) return removed