From 3afe94d337a2e3ea1405fb117b1718ee0f6043e7 Mon Sep 17 00:00:00 2001 From: dberenbaum Date: Fri, 15 Sep 2023 09:45:52 -0400 Subject: [PATCH 1/2] gc: add dry option and return num removed --- src/dvc_data/hashfile/gc.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/dvc_data/hashfile/gc.py b/src/dvc_data/hashfile/gc.py index 8d97e664..2883a80a 100644 --- a/src/dvc_data/hashfile/gc.py +++ b/src/dvc_data/hashfile/gc.py @@ -1,4 +1,4 @@ -def gc(odb, used, jobs=None, cache_odb=None, shallow=True): +def gc(odb, used, jobs=None, cache_odb=None, shallow=True, dry=False): from dvc_objects.errors import ObjectDBPermissionError from ._progress import QueryingProgress @@ -20,7 +20,7 @@ def _is_dir_hash(_hash): return _hash.endswith(HASH_DIR_SUFFIX) - removed = False + removed = 0 dir_paths = [] file_paths = [] @@ -38,7 +38,8 @@ def _is_dir_hash(_hash): for paths in (dir_paths, file_paths): if paths: - removed = True - odb.fs.remove(paths) + removed += len(paths) + if not dry: + odb.fs.remove(paths) return removed From 0fb9d1526019657d037c884c056813e99b87318c Mon Sep 17 00:00:00 2001 From: dberenbaum Date: Fri, 22 Sep 2023 12:30:17 -0400 Subject: [PATCH 2/2] rename removed to num_removed --- src/dvc_data/hashfile/gc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dvc_data/hashfile/gc.py b/src/dvc_data/hashfile/gc.py index 2883a80a..9dfb0449 100644 --- a/src/dvc_data/hashfile/gc.py +++ b/src/dvc_data/hashfile/gc.py @@ -20,7 +20,7 @@ def _is_dir_hash(_hash): return _hash.endswith(HASH_DIR_SUFFIX) - removed = 0 + num_removed = 0 dir_paths = [] file_paths = [] @@ -38,8 +38,8 @@ def _is_dir_hash(_hash): for paths in (dir_paths, file_paths): if paths: - removed += len(paths) + num_removed += len(paths) if not dry: odb.fs.remove(paths) - return removed + return num_removed