Skip to content

Commit

Permalink
get: recoup cache optimal location
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode committed Jan 10, 2020
1 parent f126f24 commit 86b9a1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions dvc/external_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions dvc/repo/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import shortuuid

from dvc.cache import CacheConfig
from dvc.config import Config
from dvc.exceptions import (
DvcException,
NotDvcRepoError,
Expand Down Expand Up @@ -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.
#
Expand All @@ -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):
Expand Down

0 comments on commit 86b9a1c

Please sign in to comment.