Skip to content

Commit

Permalink
dvc: update gc to remove unpacked dir
Browse files Browse the repository at this point in the history
In local remote its found that gc does not
remove the unpacked dir. This change set
helps to remove it.

Signed-off-by: Sujith H <[email protected]>
  • Loading branch information
sharidasan committed Jan 6, 2020
1 parent 8041d70 commit 1e3abe2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dvc/remote/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,8 @@ def gc(self, named_cache):
if checksum in used:
continue
path_info = self.checksum_to_path_info(checksum)
if self.is_dir_checksum(checksum):
self._remove_unpacked_dir(checksum)
self.remove(path_info)
removed = True
return removed
Expand Down Expand Up @@ -1009,3 +1011,6 @@ def _changed_unpacked_dir(self, checksum):

def _update_unpacked_dir(self, checksum):
pass

def _remove_unpacked_dir(self, checksum):
pass
4 changes: 4 additions & 0 deletions dvc/remote/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ def _get_unpacked_dir_path_info(self, checksum):
info = self.checksum_to_path_info(checksum)
return info.with_name(info.name + self.UNPACKED_DIR_SUFFIX)

def _remove_unpacked_dir(self, checksum):
path_info = self._get_unpacked_dir_path_info(checksum)
self.remove(path_info)

def _path_info_changed(self, path_info):
if self.exists(path_info) and self.state.get(path_info):
return False
Expand Down
16 changes: 16 additions & 0 deletions tests/func/test_gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dvc.exceptions import CollectCacheError
from dvc.main import main
from dvc.repo import Repo as DvcRepo
from dvc.remote.local import RemoteLOCAL
from tests.basic_env import TestDir, TestDvcGit


Expand Down Expand Up @@ -204,3 +205,18 @@ def test_gc_no_dir_cache(tmp_dir, dvc, repo_template):

def _count_files(path):
return sum(len(files) for _, _, files in os.walk(path))


def test_gc_no_unpacked_dir(tmp_dir, dvc, repo_template):
dir_stages = dvc.add("dir")
dvc.status()

os.remove("dir.dvc")
unpackeddir = (
dir_stages[0].outs[0].cache_path + RemoteLOCAL.UNPACKED_DIR_SUFFIX
)

assert os.path.exists(unpackeddir)

dvc.gc(force=True)
assert not os.path.exists(unpackeddir)

0 comments on commit 1e3abe2

Please sign in to comment.