From e505c38f203e7de972b52272b49d3317f4090ecb Mon Sep 17 00:00:00 2001 From: pared Date: Sat, 6 Apr 2019 13:58:11 +0200 Subject: [PATCH] cache: make reflink, copy default links --- dvc/remote/local.py | 6 ++++-- tests/test_cache.py | 5 +++++ tests/test_checkout.py | 21 ++++++++++++++------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/dvc/remote/local.py b/dvc/remote/local.py index 112336365..04c043d3a 100644 --- a/dvc/remote/local.py +++ b/dvc/remote/local.py @@ -1,5 +1,7 @@ from __future__ import unicode_literals +from copy import copy + from dvc.utils.compat import str, makedirs import os @@ -49,7 +51,7 @@ class RemoteLOCAL(RemoteBase): PARAM_RELPATH = "relpath" MD5_DIR_SUFFIX = ".dir" - CACHE_TYPES = ["reflink", "hardlink", "symlink", "copy"] + DEFAULT_CACHE_TYPES = ["reflink", "copy"] CACHE_TYPE_MAP = { "copy": shutil.copyfile, "symlink": System.symlink, @@ -74,7 +76,7 @@ class RemoteLOCAL(RemoteBase): types = [t.strip() for t in types.split(",")] self.cache_types = types else: - self.cache_types = self.CACHE_TYPES + self.cache_types = copy(self.DEFAULT_CACHE_TYPES) if self.cache_dir is not None and not os.path.exists(self.cache_dir): os.mkdir(self.cache_dir) diff --git a/tests/test_cache.py b/tests/test_cache.py index 9fbba5fcd..9e0bd1dad 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -168,3 +168,8 @@ class TestCmdCacheDir(TestDvc): self.assertEqual(len(subdirs), 1) files = os.listdir(os.path.join(tmpdir, subdirs[0])) self.assertEqual(len(files), 1) + + +class TestShouldCacheBeReflinkOrCopyByDefault(TestDvc): + def test(self): + self.assertEqual(self.dvc.cache.local.cache_types, ["reflink", "copy"]) diff --git a/tests/test_checkout.py b/tests/test_checkout.py index f987f1376..6abe2de98 100644 --- a/tests/test_checkout.py +++ b/tests/test_checkout.py @@ -12,7 +12,7 @@ from dvc.main import main from dvc import progress from dvc.repo import Repo as DvcRepo from dvc.system import System -from dvc.utils import walk_files +from dvc.utils import walk_files, load_stage_file from tests.basic_env import TestDvc from tests.test_repro import TestRepro from dvc.stage import Stage, StageFileBadNameError, StageFileDoesNotExistError @@ -134,7 +134,9 @@ class CheckoutBase(TestDvc): FileInfo = collections.namedtuple("FileInfo", "path inode") paths = [ - path for output in stage.outs for path in walk_files(output.path) + path + for output in stage["outs"] + for path in walk_files(output["path"]) ] return [ @@ -210,14 +212,19 @@ class TestCheckoutSelectiveRemove(CheckoutBase): ret = main(["config", "cache.type", "copy"]) self.assertEqual(ret, 0) - stages = self.dvc.add(self.DATA_DIR) - self.assertEqual(len(stages), 1) - stage = stages[0] + ret = main(["add", self.DATA_DIR]) + self.assertEqual(0, ret) + + stage_path = self.DATA_DIR + Stage.STAGE_FILE_SUFFIX + stage = load_stage_file(stage_path) staged_files = self.outs_info(stage) - os.remove(staged_files[0].path) + # move instead of remove, to lock inode assigned to stage_files[0].path + # if we were to use remove, we might end up with same inode assigned to + # newly checked out file + shutil.move(staged_files[0].path, "random_name") - ret = main(["checkout", "--force", stage.relpath]) + ret = main(["checkout", "--force", stage_path]) self.assertEqual(ret, 0) checkedout_files = self.outs_info(stage)