Skip to content

Commit b860576

Browse files
committed
Add isreserved
1 parent fde971e commit b860576

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

dissect/target/helpers/fsutil.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
commonpath,
4343
dirname,
4444
isabs,
45+
isreserved,
4546
join,
4647
normalize,
4748
normpath,
@@ -82,6 +83,7 @@
8283
"glob_split",
8384
"has_glob_magic",
8485
"isabs",
86+
"isreserved",
8587
"join",
8688
"normalize",
8789
"normpath",

dissect/target/helpers/polypath.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,11 @@ def relpath(path: str, start: str, alt_separator: str = "") -> str:
7171

7272
def commonpath(paths: list[str], alt_separator: str = "") -> str:
7373
return posixpath.commonpath([normalize(path, alt_separator=alt_separator) for path in paths])
74+
75+
76+
def isreserved(path: str) -> bool:
77+
"""Return True if the path is a reserved name.
78+
79+
We currently do not have any reserved names.
80+
"""
81+
return False

tests/helpers/test_fsutil.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,26 @@ def test_relpath(path: str, start: str, alt_separator: str, result: str) -> None
165165
assert fsutil.relpath(path, start, alt_separator=alt_separator) == result
166166

167167

168+
@pytest.mark.parametrize(
169+
("paths, alt_separator, result"),
170+
[
171+
(["/some/dir/some/file", "/some/dir/some/other"], "", "/some/dir/some"),
172+
(["/some/dir/some/file", "/some/dir/some/other"], "\\", "/some/dir/some"),
173+
(["\\some\\dir\\some\\file", "\\some\\dir\\some\\other"], "\\", "/some/dir/some"),
174+
(["/some/dir/some/file", "/some/dir/other"], "", "/some/dir"),
175+
(["/some/dir/some/file", "/some/other"], "", "/some"),
176+
(["/some/dir/some/file", "/some/other"], "\\", "/some"),
177+
],
178+
)
179+
def test_commonpath(paths: list[str], alt_separator: str, result: str) -> None:
180+
assert fsutil.commonpath(paths, alt_separator=alt_separator) == result
181+
182+
183+
def test_isreserved() -> None:
184+
assert not fsutil.isreserved("CON")
185+
assert not fsutil.isreserved("foo")
186+
187+
168188
def test_generate_addr() -> None:
169189
slash_path = "/some/dir/some/file"
170190
slash_vfs = VirtualFilesystem(alt_separator="")
@@ -312,9 +332,10 @@ def test_target_path_is_relative_to(path_fs: VirtualFilesystem) -> None:
312332

313333

314334
def test_target_path_is_reserved(path_fs: VirtualFilesystem) -> None:
315-
# We currently do not have any reserved names for TargetPath
316-
assert not path_fs.path("CON").is_reserved()
317-
assert not path_fs.path("foo").is_reserved()
335+
if sys.version_info < (3, 13):
336+
# We currently do not have any reserved names for TargetPath
337+
assert not path_fs.path("CON").is_reserved()
338+
assert not path_fs.path("foo").is_reserved()
318339

319340

320341
def test_target_path_join(path_fs: VirtualFilesystem) -> None:

0 commit comments

Comments
 (0)