Skip to content

Commit

Permalink
dvc: address review from iterative#2160
Browse files Browse the repository at this point in the history
Signed-off-by: Ruslan Kuprieiev <[email protected]>
  • Loading branch information
efiop committed Jun 21, 2019
1 parent 95096e5 commit d795cdf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
24 changes: 11 additions & 13 deletions dvc/external_repo.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from __future__ import unicode_literals

import os
import uuid
import errno
import shutil
import logging
import shortuuid

from funcy import cached_property
from schema import Optional

from dvc.config import Config
from dvc.cache import CacheConfig
from dvc.exceptions import DvcException
from dvc.utils.compat import makedirs


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -98,9 +100,6 @@ def _install_to(self, tmp_dir, cache_dir):
cache_config.set_dir(cache_dir, level=Config.LEVEL_LOCAL)
repo.scm.git.close()

if self.installed:
self.uninstall()

def install(self, cache_dir=None, force=False):
if self.installed and not force:
logger.info(
Expand All @@ -109,25 +108,24 @@ def install(self, cache_dir=None, force=False):
)
return

try:
os.makedirs(self.repos_dir)
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
makedirs(self.repos_dir, exist_ok=True)

# installing package to a temporary directory until we are sure that
# it has been installed correctly.
#
# Note that tempfile.TemporaryDirectory is using symlinks to tmpfs, so
# we won't be able to use move properly.
tmp_dir = os.path.join(self.repos_dir, "." + str(uuid.uuid4()))
# Note that we can't use tempfile.TemporaryDirectory is using symlinks
# to tmpfs, so we won't be able to use move properly.
tmp_dir = os.path.join(self.repos_dir, "." + str(shortuuid.uuid()))
try:
self._install_to(tmp_dir, cache_dir)
except ExternalRepoError:
if os.path.exists(tmp_dir):
shutil.rmtree(tmp_dir)
raise

if self.installed:
self.uninstall()

shutil.move(tmp_dir, self.path)

def uninstall(self):
Expand Down
4 changes: 2 additions & 2 deletions dvc/repo/get_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def get_url(url, out=None):
out = out or os.path.basename(urlparse(url).path)

if os.path.exists(url):
src = os.path.abspath(url)
url = os.path.abspath(url)
out = os.path.abspath(out)

dep, = dependency.loads_from(None, [src])
dep, = dependency.loads_from(None, [url])
out, = output.loads_from(None, [out], use_cache=False)
dep.download(out)

0 comments on commit d795cdf

Please sign in to comment.