From bdaf4aced6746f9b6b1fc4401d691b5f83d95560 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sat, 25 Sep 2021 02:11:35 +0300 Subject: [PATCH] state: cleanup redundant or localfs-specific logic (#6684) Pre-requisite for making state work with other filesystems. --- dvc/state.py | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/dvc/state.py b/dvc/state.py index 4881a62ef..ffdb051e3 100644 --- a/dvc/state.py +++ b/dvc/state.py @@ -79,11 +79,6 @@ class State(StateBase): # pylint: disable=too-many-instance-attributes if not isinstance(fs, LocalFileSystem): return - assert isinstance(path_info, str) or path_info.scheme == "local" - assert hash_info - assert isinstance(hash_info, HashInfo) - assert os.path.exists(path_info) - mtime, size = get_mtime_and_size(path_info, fs, self.dvcignore) inode = get_inode(path_info) @@ -111,17 +106,12 @@ class State(StateBase): # pylint: disable=too-many-instance-attributes if not isinstance(fs, LocalFileSystem): return None - assert isinstance(path_info, str) or path_info.scheme == "local" - path = os.fspath(path_info) - - # NOTE: use os.path.exists instead of LocalFileSystem.exists - # because it uses lexists() and will return True for broken - # symlinks that we cannot stat() in get_mtime_and_size - if not os.path.exists(path): + try: + mtime, size = get_mtime_and_size(path_info, fs, self.dvcignore) + except FileNotFoundError: return None - mtime, size = get_mtime_and_size(path, fs, self.dvcignore) - inode = get_inode(path) + inode = get_inode(path_info) value = self.md5s.get(inode) @@ -140,12 +130,11 @@ class State(StateBase): # pylint: disable=too-many-instance-attributes if not isinstance(fs, LocalFileSystem): return - assert isinstance(path_info, str) or path_info.scheme == "local" - - if not fs.exists(path_info): + try: + mtime, _ = get_mtime_and_size(path_info, fs, self.dvcignore) + except FileNotFoundError: return - mtime, _ = get_mtime_and_size(path_info, fs, self.dvcignore) inode = get_inode(path_info) relative_path = relpath(path_info, self.root_dir)