From 20bb6ddf3cc2bd8876794f88b27ec167b1780ef9 Mon Sep 17 00:00:00 2001 From: Anas Chetouan Date: Sat, 2 Oct 2021 15:06:42 +0200 Subject: [PATCH] doctor: fixes unknown cache directory error on some windows mapped network shares (#6364) * doctor: fixes unknown cache director error on some windows mapped network shares On Windows, resolve calls os.path._getfinalpathname, which calls GetFinalPathNameByHandle. This starts from the final resolved path of the file in the NT namespace (e.g. \Device\Mup\server\share...) and works backward as required to get the VOLUME_NAME_DOS. If the final path is a UNC share (i.e. \Device\Mup), We fix this by calling resolve() also on the partition mountpoints We also take the opportunity to make checks in case a PermissionError is returned to us Fixes github.com/iterative/dvc/issues/6305 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * doctor: fixes unknown cache director error on some windows mapped network shares On Windows, resolve calls os.path._getfinalpathname, which calls GetFinalPathNameByHandle. This starts from the final resolved path of the file in the NT namespace (e.g. \Device\Mup\server\share...) and works backward as required to get the VOLUME_NAME_DOS. If the final path is a UNC share (i.e. \Device\Mup), We fix this by calling resolve() also on the partition mountpoints We also take the opportunity to make checks in case a PermissionError is returned to us Fixes #6305 Co-authored-by: CHETOUAN Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: CHETOUAN --- dvc/info.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/dvc/info.py b/dvc/info.py index ec2420d7f..577934b95 100644 --- a/dvc/info.py +++ b/dvc/info.py @@ -136,11 +136,14 @@ def _get_supported_remotes(): def get_fs_type(path): - - partition = { - pathlib.Path(part.mountpoint): (part.fstype + " on " + part.device) - for part in psutil.disk_partitions(all=True) - } + partition = {} + for part in psutil.disk_partitions(all=True): + if part.fstype != "": + try: + mountpoint = pathlib.Path(part.mountpoint).resolve() + partition[mountpoint] = part.fstype + " on " + part.device + except PermissionError: + pass # need to follow the symlink: https://github.com/iterative/dvc/issues/5065 path = pathlib.Path(path).resolve()