Skip to content

Commit 7564775

Browse files
committed
Handle cross-mount paths in find_parents
1 parent bc1095f commit 7564775

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

pylsp/_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ def find_parents(root, path, names):
9696
# Split the relative by directory, generate all the parent directories, then check each of them.
9797
# This avoids running a loop that has different base-cases for unix/windows
9898
# e.g. /a/b and /a/b/c/d/e.py -> ['/a/b', 'c', 'd']
99-
dirs = [root] + os.path.relpath(os.path.dirname(path), root).split(os.path.sep)
99+
try:
100+
dirs = [root] + os.path.relpath(os.path.dirname(path), root).split(os.path.sep)
101+
except ValueError:
102+
log.warning("Path %r not in %r", path, root)
103+
return []
100104

101105
# Search each of /a/b/c, /a/b, /a
102106
while dirs:

test/test_utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright 2021- Python Language Server Contributors.
33

44
import multiprocessing
5+
import ntpath
56
import os
67
import sys
78
import time
@@ -197,6 +198,19 @@ def test_find_parents(tmpdir) -> None:
197198
]
198199

199200

201+
def test_find_parents_handles_cross_mount_paths(monkeypatch) -> None:
202+
monkeypatch.setattr(_utils.os, "path", ntpath)
203+
204+
assert (
205+
_utils.find_parents(
206+
r"\\server\share1",
207+
r"\\server\share2\path.py",
208+
["test.cfg"],
209+
)
210+
== []
211+
)
212+
213+
200214
def test_merge_dicts() -> None:
201215
assert _utils.merge_dicts(
202216
{"a": True, "b": {"x": 123, "y": {"hello": "world"}}},

0 commit comments

Comments
 (0)