From 48641fb41f07514acc352f406c5ea5d3c1243f96 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Fri, 28 Jan 2022 18:09:33 +0200 Subject: [PATCH] repofs: don't use outs Using outs directly breaks isolation and makes it really hard to understand what's going on. Redundant abspaths will go away in followups when moving to relpaths. --- dvc/fs/repo.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/dvc/fs/repo.py b/dvc/fs/repo.py index edd68153a..0f57128b6 100644 --- a/dvc/fs/repo.py +++ b/dvc/fs/repo.py @@ -220,6 +220,8 @@ class RepoFileSystem(FileSystem): # pylint:disable=abstract-method return dvc_fs.open(path, mode=mode, encoding=encoding, **kwargs) def exists(self, path) -> bool: + path = os.path.abspath(path) + fs, dvc_fs = self._get_fs_pair(path) if not dvc_fs: @@ -231,18 +233,21 @@ class RepoFileSystem(FileSystem): # pylint:disable=abstract-method if fs.exists(path): return True - try: - info = dvc_fs.info(path) - except FileNotFoundError: + if not dvc_fs.exists(path): return False - for out in info["outs"]: - if fs.exists(out.fs_path): - return False + for p in self.path.parents(path): + try: + if fs.info(p)["type"] != "directory": + return False + except FileNotFoundError: + continue return True def isdir(self, path): # pylint: disable=arguments-renamed + path = os.path.abspath(path) + fs, dvc_fs = self._get_fs_pair(path) if dvc_fs and dvc_fs.repo.dvcignore.is_ignored_dir(path): @@ -263,9 +268,12 @@ class RepoFileSystem(FileSystem): # pylint:disable=abstract-method except FileNotFoundError: return False - for out in info["outs"]: - if fs.exists(out.fs_path): - return False + for p in self.path.parents(path): + try: + if fs.info(p)["type"] != "directory": + return False + except FileNotFoundError: + continue return info["type"] == "directory" @@ -274,6 +282,8 @@ class RepoFileSystem(FileSystem): # pylint:disable=abstract-method return dvc_fs is not None and dvc_fs.isdvc(path, **kwargs) def isfile(self, path): # pylint: disable=arguments-renamed + path = os.path.abspath(path) + fs, dvc_fs = self._get_fs_pair(path) if dvc_fs and dvc_fs.repo.dvcignore.is_ignored_file(path): @@ -294,10 +304,12 @@ class RepoFileSystem(FileSystem): # pylint:disable=abstract-method except FileNotFoundError: return False - (out,) = info["outs"] - assert len(info["outs"]) == 1 - if fs.exists(out.fs_path): - return False + for p in self.path.parents(path): + try: + if fs.info(p)["type"] != "directory": + return False + except FileNotFoundError: + continue return info["type"] == "file"