From f3d234ec9cb933009d39531e15edcd80e2059a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Fri, 10 Jan 2020 23:26:37 +0000 Subject: [PATCH] deduplicate code --- dvc/repo/get.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/dvc/repo/get.py b/dvc/repo/get.py index a1f99f671..3c417556c 100644 --- a/dvc/repo/get.py +++ b/dvc/repo/get.py @@ -27,11 +27,6 @@ class GetDVCFileError(DvcException): ) -def _forbid_absolute_path(path): - if os.path.isabs(path): - raise FileNotFoundError - - @staticmethod def get(url, path, out=None, rev=None): out = resolve_output(path, out) @@ -46,6 +41,7 @@ def get(url, path, out=None, rev=None): # and won't work with reflink/hardlink. dpath = os.path.dirname(os.path.abspath(out)) tmp_dir = os.path.join(dpath, "." + str(shortuuid.uuid())) + repo_dir = None try: try: with external_repo(cache_dir=tmp_dir, url=url, rev=rev) as repo: @@ -70,18 +66,20 @@ def get(url, path, out=None, rev=None): return # Either an uncached out with absolute path or a user error - _forbid_absolute_path(path) - fs_copy(os.path.join(repo.root_dir, path), out) - return + repo_dir = repo.root_dir except NotDvcRepoError: # Not a DVC repository, continue below and copy from git pass - _forbid_absolute_path(path) - raw_git_dir = cached_clone(url, rev=rev) - fs_copy(os.path.join(raw_git_dir, path), out) + if os.path.isabs(path): + raise FileNotFoundError + + if not repo_dir: + repo_dir = cached_clone(url, rev=rev) + + fs_copy(os.path.join(repo_dir, path), out) except (OutputNotFoundError, FileNotFoundError): raise PathMissingError(path, url) finally: