get: recoup cache optimal location

This commit is contained in:
Fábio Santos
2020-01-10 22:28:24 +00:00
parent f126f2483b
commit 86b9a1cfe4
2 changed files with 10 additions and 5 deletions
+2 -2
View File
@@ -33,7 +33,7 @@ def external_repo(url=None, rev=None, rev_lock=None, cache_dir=None):
repo.close()
def cached_clone(url, rev=None, clone_path=None, **_ignored_kwargs):
def cached_clone(url, rev=None, **_ignored_kwargs):
"""Clone an external git repo to a temporary directory.
Returns the path to a local temporary directory with the specified
@@ -44,7 +44,7 @@ def cached_clone(url, rev=None, clone_path=None, **_ignored_kwargs):
"""
new_path = clone_path or tempfile.mkdtemp("dvc-erepo")
new_path = tempfile.mkdtemp("dvc-erepo")
# Copy and adjust existing clean clone
if (url, None, None) in REPO_CACHE:
+8 -3
View File
@@ -3,6 +3,8 @@ import os
import shortuuid
from dvc.cache import CacheConfig
from dvc.config import Config
from dvc.exceptions import (
DvcException,
NotDvcRepoError,
@@ -49,9 +51,11 @@ def get(url, path, out=None, rev=None):
dpath = os.path.dirname(os.path.abspath(out))
tmp_dir = os.path.join(dpath, "." + str(shortuuid.uuid()))
try:
cached_clone(url, rev=rev, clone_path=tmp_dir)
clone_dir = cached_clone(url, rev=rev)
try:
repo = Repo(tmp_dir)
repo = Repo(clone_dir)
cache_config = CacheConfig(repo.config)
cache_config.set_dir(tmp_dir, level=Config.LEVEL_LOCAL)
# Try any links possible to avoid data duplication.
#
@@ -78,12 +82,13 @@ def get(url, path, out=None, rev=None):
if os.path.isabs(path):
raise FileNotFoundError
fs_copy(os.path.join(tmp_dir, path), out)
fs_copy(os.path.join(clone_dir, path), out)
except (OutputNotFoundError, FileNotFoundError):
raise PathMissingError(path, url)
finally:
remove(tmp_dir)
remove(clone_dir)
def _get_cached(repo, output, out):