mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
output: base: don't forget to return empty cache (#2656)
* output: base: don't forget to return empty cache CC @Suor Fixes https://gist.github.com/leimbernon/21924e02a998e3f1604990f8a7824c37 Signed-off-by: Ruslan Kuprieiev <[email protected]> * gc: add test for missing .dir cache file
This commit is contained in:
@@ -325,3 +325,7 @@ class CheckoutError(DvcException):
|
||||
"forget to fetch?".format("\n".join(targets))
|
||||
)
|
||||
super(CheckoutError, self).__init__(m)
|
||||
|
||||
|
||||
class CollectCacheError(DvcException):
|
||||
pass
|
||||
|
||||
+4
-5
@@ -7,7 +7,7 @@ from schema import Or, Optional
|
||||
|
||||
from dvc.cache import NamedCache
|
||||
import dvc.prompt as prompt
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.exceptions import DvcException, CollectCacheError
|
||||
from dvc.utils.compat import str, urlparse
|
||||
from dvc.remote.base import RemoteBASE
|
||||
|
||||
@@ -353,7 +353,7 @@ class OutputBase(object):
|
||||
nc.add(self.scheme, 'd3b07384d113', 'directory/bar')
|
||||
"""
|
||||
|
||||
ret = []
|
||||
cache = NamedCache()
|
||||
|
||||
if self.cache.changed_cache_file(self.checksum):
|
||||
try:
|
||||
@@ -373,14 +373,13 @@ class OutputBase(object):
|
||||
"Would you like to continue? Use '-f' to force."
|
||||
)
|
||||
if not force and not prompt.confirm(msg.format(self.path_info)):
|
||||
raise DvcException(
|
||||
raise CollectCacheError(
|
||||
"unable to fully collect used cache"
|
||||
" without cache for directory '{}'".format(self)
|
||||
)
|
||||
else:
|
||||
return ret
|
||||
return cache
|
||||
|
||||
cache = NamedCache()
|
||||
for entry in self.dir_cache:
|
||||
checksum = entry[self.remote.PARAM_CHECKSUM]
|
||||
path_info = self.path_info / entry[self.remote.PARAM_RELPATH]
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import os
|
||||
|
||||
import pytest
|
||||
import configobj
|
||||
|
||||
from git import Repo
|
||||
@@ -7,6 +9,7 @@ from git import Repo
|
||||
from dvc.utils.compat import pathlib
|
||||
from dvc.main import main
|
||||
from dvc.repo import Repo as DvcRepo
|
||||
from dvc.exceptions import CollectCacheError
|
||||
|
||||
from tests.basic_env import TestDvcGit
|
||||
from tests.basic_env import TestDir
|
||||
@@ -208,3 +211,20 @@ def test_all_commits(git, dvc_repo):
|
||||
|
||||
def _count_files(path):
|
||||
return sum(len(files) for _, _, files in os.walk(path))
|
||||
|
||||
|
||||
def test_gc_no_dir_cache(repo_dir, dvc_repo):
|
||||
dvc_repo.add(repo_dir.FOO)
|
||||
dvc_repo.add(repo_dir.BAR)
|
||||
dir_stage, = dvc_repo.add(repo_dir.DATA_DIR)
|
||||
|
||||
os.unlink(dir_stage.outs[0].cache_path)
|
||||
|
||||
with pytest.raises(CollectCacheError):
|
||||
dvc_repo.gc()
|
||||
|
||||
assert _count_files(dvc_repo.cache.local.cache_dir) == 4
|
||||
|
||||
dvc_repo.gc(force=True)
|
||||
|
||||
assert _count_files(dvc_repo.cache.local.cache_dir) == 2
|
||||
|
||||
Reference in New Issue
Block a user