Skip to content

Commit

Permalink
Merge pull request #3018 from pared/2914_3
Browse files Browse the repository at this point in the history
local-related methods should verify that WorkingTree is in use
  • Loading branch information
efiop authored Jan 5, 2020
2 parents 7f92cc3 + 3642738 commit 29afb38
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
9 changes: 3 additions & 6 deletions dvc/remote/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from dvc.exceptions import DownloadError
from dvc.exceptions import DvcException
from dvc.exceptions import UploadError
from dvc.ignore import CleanTree
from dvc.path_info import PathInfo
from dvc.progress import Tqdm
from dvc.remote.base import RemoteBASE
Expand All @@ -20,7 +19,7 @@
from dvc.remote.base import STATUS_MISSING
from dvc.remote.base import STATUS_NEW
from dvc.scheme import Schemes
from dvc.scm.tree import WorkingTree
from dvc.scm.tree import is_working_tree
from dvc.system import System
from dvc.utils import copyfile
from dvc.utils import file_md5
Expand Down Expand Up @@ -136,9 +135,7 @@ def getsize(path_info):
return os.path.getsize(fspath_py35(path_info))

def walk_files(self, path_info):
assert isinstance(self.repo.tree, CleanTree) and isinstance(
self.repo.tree.tree, WorkingTree
)
assert is_working_tree(self.repo.tree)

for fname in self.repo.tree.walk_files(path_info):
yield PathInfo(fname)
Expand Down Expand Up @@ -429,7 +426,7 @@ def _unprotect_file(path):
os.chmod(path, os.stat(path).st_mode | stat.S_IWRITE)

def _unprotect_dir(self, path):
assert isinstance(self.repo.tree, CleanTree)
assert is_working_tree(self.repo.tree)

for fname in self.repo.tree.walk_files(path):
RemoteLOCAL._unprotect_file(fname)
Expand Down
6 changes: 6 additions & 0 deletions dvc/scm/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ def onerror(e):
top, topdown=topdown, onerror=onerror
):
yield os.path.normpath(root), dirs, files


def is_working_tree(tree):
return isinstance(tree, WorkingTree) or isinstance(
getattr(tree, "tree", None), WorkingTree
)
6 changes: 3 additions & 3 deletions dvc/utils/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from shortuuid import uuid

from dvc.exceptions import DvcException
from dvc.scm.tree import is_working_tree
from dvc.system import System
from dvc.utils import dict_md5
from dvc.utils import fspath
Expand All @@ -32,11 +33,10 @@ def get_inode(path):


def get_mtime_and_size(path, tree):
from dvc.ignore import CleanTree

assert isinstance(tree, CleanTree)

if os.path.isdir(fspath_py35(path)):
assert is_working_tree(tree)

size = 0
files_mtimes = {}
for file_path in tree.walk_files(path):
Expand Down

0 comments on commit 29afb38

Please sign in to comment.