Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dvc: move temporary files to .dvc/tmp #3725

Merged
merged 1 commit into from
May 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dvc/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, args):
self.config = self.repo.config
self.args = args
hardlink_lock = self.config["core"].get("hardlink_lock", False)
updater = Updater(self.repo.dvc_dir, hardlink_lock=hardlink_lock)
updater = Updater(self.repo.tmp_dir, hardlink_lock=hardlink_lock)
updater.check()

@property
Expand Down
3 changes: 2 additions & 1 deletion dvc/command/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ def run(self):

root_dir = Repo.find_root()
dvc_dir = os.path.join(root_dir, Repo.DVC_DIR)
tmp_dir = os.path.join(dvc_dir, "tmp")
config = Config(dvc_dir, validate=False)
hardlink_lock = config.get("core", {}).get("hardlink_lock", False)
updater = Updater(dvc_dir, hardlink_lock=hardlink_lock)
updater = Updater(tmp_dir, hardlink_lock=hardlink_lock)
updater.fetch(detach=False)

return 0
Expand Down
2 changes: 1 addition & 1 deletion dvc/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
FAILED_TO_LOCK_MESSAGE = (
"cannot perform the command because another DVC process seems to be "
"running on this project. If that is not the case, manually remove "
"`.dvc/lock` and try again."
"`.dvc/tmp/lock` and try again."
)


Expand Down
14 changes: 3 additions & 11 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def __init__(self, root_dir=None):

hardlink_lock = self.config["core"].get("hardlink_lock", False)
self.lock = make_lock(
os.path.join(self.dvc_dir, "lock"),
tmp_dir=os.path.join(self.dvc_dir, "tmp"),
os.path.join(self.tmp_dir, "lock"),
tmp_dir=self.tmp_dir,
hardlink_lock=hardlink_lock,
friendly=True,
)
Expand Down Expand Up @@ -164,15 +164,7 @@ def unprotect(self, target):
return self.cache.local.unprotect(PathInfo(target))

def _ignore(self):
from dvc.updater import Updater

updater = Updater(self.dvc_dir)

flist = (
[self.config.files["local"], updater.updater_file]
+ [self.lock.lockfile, updater.lock.lockfile, self.tmp_dir]
+ self.state.files
)
flist = [self.config.files["local"], self.tmp_dir]

if path_isin(self.cache.local.cache_dir, self.root_dir):
flist += [self.cache.local.cache_dir]
Expand Down
5 changes: 2 additions & 3 deletions dvc/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class State(object): # pylint: disable=too-many-instance-attributes

def __init__(self, repo):
self.repo = repo
self.dvc_dir = repo.dvc_dir
self.root_dir = repo.root_dir

state_config = repo.config.get("state", {})
Expand All @@ -105,11 +104,11 @@ def __init__(self, repo):
"row_cleanup_quota", self.STATE_ROW_CLEANUP_QUOTA
)

if not self.dvc_dir:
if not repo.tmp_dir:
self.state_file = None
return

self.state_file = os.path.join(self.dvc_dir, self.STATE_FILE)
self.state_file = os.path.join(repo.tmp_dir, self.STATE_FILE)

# https://www.sqlite.org/tempfiles.html
self.temp_files = [
Expand Down
7 changes: 3 additions & 4 deletions dvc/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ class Updater(object): # pragma: no cover
TIMEOUT = 24 * 60 * 60 # every day
TIMEOUT_GET = 10

def __init__(self, dvc_dir, friendly=False, hardlink_lock=False):
self.dvc_dir = dvc_dir
self.updater_file = os.path.join(dvc_dir, self.UPDATER_FILE)
def __init__(self, tmp_dir, friendly=False, hardlink_lock=False):
self.updater_file = os.path.join(tmp_dir, self.UPDATER_FILE)
self.lock = make_lock(
self.updater_file + ".lock",
tmp_dir=os.path.join(dvc_dir, "tmp"),
tmp_dir=tmp_dir,
friendly=friendly,
hardlink_lock=hardlink_lock,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/func/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_no_cache_entry(tmp_dir, scm, dvc):
tmp_dir.dvc_gen("file", "second")

remove(fspath(tmp_dir / ".dvc" / "cache"))
(tmp_dir / ".dvc" / "state").unlink()
(tmp_dir / ".dvc" / "tmp" / "state").unlink()

dir_checksum = "5fb6b29836c388e093ca0715c872fe2a.dir"

Expand Down
4 changes: 2 additions & 2 deletions tests/func/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class TestLock(TestDvc):
def test_with(self):
lockfile = os.path.join(self.dvc.dvc_dir, "lock")
lockfile = os.path.join(self.dvc.dvc_dir, "tmp", "lock")
lock = Lock(lockfile)
with lock:
with self.assertRaises(LockError):
Expand All @@ -17,7 +17,7 @@ def test_with(self):
self.assertTrue(False)

def test_cli(self):
lockfile = os.path.join(self.dvc.dvc_dir, "lock")
lockfile = os.path.join(self.dvc.dvc_dir, "tmp", "lock")
lock = Lock(lockfile)
with lock:
ret = main(["add", self.FOO])
Expand Down