Merge pull request #2745 from shcheklein/fix-2744

dvc get leaves dangling symlinks if source repo is set to use symlinks as its cache type
This commit is contained in:
Ruslan Kuprieiev
2019-11-06 03:08:37 +02:00
committed by GitHub
4 changed files with 46 additions and 11 deletions
+1 -6
View File
@@ -3,7 +3,6 @@ import os
import shortuuid
from dvc.config import Config
from dvc.exceptions import GetDVCFileError
from dvc.exceptions import NotDvcRepoError
from dvc.exceptions import OutputNotFoundError
@@ -48,11 +47,7 @@ def get(url, path, out=None, rev=None):
#
# Also, we can't use theoretical "move" link type here, because
# the same cache file might be used a few times in a directory.
repo.config.set(
Config.SECTION_CACHE,
Config.SECTION_CACHE_TYPE,
"reflink,hardlink,copy",
)
repo.cache.local.cache_types = ["reflink", "hardlink", "copy"]
o = repo.find_out_by_relpath(path)
with repo.state:
+5 -5
View File
@@ -188,10 +188,10 @@ def test_all_commits(git, dvc_repo):
cache_dir = os.path.join(dvc_repo.root_dir, ".dvc", "cache")
testfile = pathlib.Path("testfile")
testfile.write_text("uncommited")
testfile.write_text("uncommitted")
dvc_repo.add(str(testfile))
testfile.write_text("commited")
testfile.write_text("committed")
add_and_commit()
testfile.write_text("modified")
@@ -200,12 +200,12 @@ def test_all_commits(git, dvc_repo):
testfile.write_text("workspace")
dvc_repo.add(str(testfile))
N = _count_files(cache_dir)
n = _count_files(cache_dir)
dvc_repo.gc(all_commits=True)
# Only one uncommited file should go away
assert _count_files(cache_dir) == N - 1
# Only one uncommitted file should go away
assert _count_files(cache_dir) == n - 1
def _count_files(path):
+19
View File
@@ -5,9 +5,11 @@ import os
import pytest
from dvc.config import Config
from dvc.exceptions import GetDVCFileError
from dvc.exceptions import UrlNotDvcRepoError
from dvc.repo import Repo
from dvc.system import System
from dvc.utils import makedirs
from tests.utils import trees_equal
@@ -34,6 +36,23 @@ def test_get_repo_dir(repo_dir, erepo):
trees_equal(src, dst)
def test_cache_type_is_properly_overridden(repo_dir, erepo):
erepo.dvc.config.set(
Config.SECTION_CACHE, Config.SECTION_CACHE_TYPE, "symlink"
)
erepo.dvc.scm.add([erepo.dvc.config.config_file])
erepo.dvc.scm.commit("set cache type to symlinks")
src = erepo.FOO
dst = erepo.FOO + "_imported"
Repo.get(erepo.root_dir, src, dst)
assert not System.is_symlink(dst)
assert os.path.exists(dst)
assert os.path.isfile(dst)
def test_get_repo_rev(repo_dir, erepo):
src = "version"
dst = src
+21
View File
@@ -7,8 +7,10 @@ import shutil
import pytest
from mock import patch
from dvc.config import Config
from dvc.exceptions import DownloadError
from dvc.stage import Stage
from dvc.system import System
from dvc.utils import makedirs
from tests.utils import trees_equal
@@ -68,6 +70,25 @@ def test_pull_imported_stage(dvc_repo, erepo):
assert os.path.isfile(dst_cache)
def test_cache_type_is_properly_overridden(repo_dir, git, dvc_repo, erepo):
erepo.dvc.config.set(
Config.SECTION_CACHE, Config.SECTION_CACHE_TYPE, "symlink"
)
erepo.dvc.scm.add([erepo.dvc.config.config_file])
erepo.dvc.scm.commit("set source repo cache type to symlinks")
src = erepo.FOO
dst = erepo.FOO + "_imported"
dvc_repo.imp(erepo.root_dir, src, dst)
assert not System.is_symlink(dst)
assert os.path.exists(dst)
assert os.path.isfile(dst)
assert filecmp.cmp(repo_dir.FOO, dst, shallow=False)
assert git.git.check_ignore(dst)
def test_pull_imported_directory_stage(dvc_repo, erepo):
src = erepo.DATA_DIR
dst = erepo.DATA_DIR + "_imported"