77 DvcException ,
88 NotDvcRepoError ,
99 OutputNotFoundError ,
10- UrlNotDvcRepoError ,
1110 PathMissingError ,
1211)
13- from dvc .external_repo import external_repo
12+ from dvc .external_repo import cached_clone
1413from dvc .path_info import PathInfo
1514from dvc .stage import Stage
1615from dvc .utils import resolve_output
@@ -28,8 +27,15 @@ def __init__(self):
2827 )
2928
3029
30+ # Dummy exception raised to signal a plain file copy is needed
31+ class _DoPlainCopy (DvcException ):
32+ pass
33+
34+
3135@staticmethod
3236def get (url , path , out = None , rev = None ):
37+ from dvc .repo import Repo
38+
3339 out = resolve_output (path , out )
3440
3541 if Stage .is_valid_filename (out ):
@@ -43,7 +49,8 @@ def get(url, path, out=None, rev=None):
4349 dpath = os .path .dirname (os .path .abspath (out ))
4450 tmp_dir = os .path .join (dpath , "." + str (shortuuid .uuid ()))
4551 try :
46- with external_repo (cache_dir = tmp_dir , url = url , rev = rev ) as repo :
52+ cached_clone (url , rev = rev , clone_path = tmp_dir )
53+ try :
4754 # Try any links possible to avoid data duplication.
4855 #
4956 # Not using symlink, because we need to remove cache after we are
@@ -53,26 +60,24 @@ def get(url, path, out=None, rev=None):
5360 #
5461 # Also, we can't use theoretical "move" link type here, because
5562 # the same cache file might be used a few times in a directory.
63+ repo = Repo (tmp_dir )
5664 repo .cache .local .cache_types = ["reflink" , "hardlink" , "copy" ]
65+ output = repo .find_out_by_relpath (path )
66+ if not output .use_cache :
67+ # Catch this below and go for a plain old fs_copy
68+ raise _DoPlainCopy
69+ _get_cached (repo , output , out )
5770
58- try :
59- output = repo .find_out_by_relpath (path )
60- except OutputNotFoundError :
61- output = None
62-
63- if output and output .use_cache :
64- _get_cached (repo , output , out )
65- else :
66- # Either an uncached out with absolute path or a user error
67- if os .path .isabs (path ):
68- raise FileNotFoundError
71+ except (NotDvcRepoError , OutputNotFoundError , _DoPlainCopy ):
72+ # It's an uncached out with absolute path, a non-DVC repo, or a
73+ # user error
74+ if os .path .isabs (path ):
75+ raise FileNotFoundError
6976
70- fs_copy (os .path .join (repo . root_dir , path ), out )
77+ fs_copy (os .path .join (tmp_dir , path ), out )
7178
7279 except (OutputNotFoundError , FileNotFoundError ):
7380 raise PathMissingError (path , url )
74- except NotDvcRepoError :
75- raise UrlNotDvcRepoError (url )
7681 finally :
7782 remove (tmp_dir )
7883
0 commit comments