Skip to content

Commit

Permalink
Add isreserved
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper committed Dec 6, 2024
1 parent fde971e commit b860576
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions dissect/target/helpers/fsutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
commonpath,
dirname,
isabs,
isreserved,
join,
normalize,
normpath,
Expand Down Expand Up @@ -82,6 +83,7 @@
"glob_split",
"has_glob_magic",
"isabs",
"isreserved",
"join",
"normalize",
"normpath",
Expand Down
8 changes: 8 additions & 0 deletions dissect/target/helpers/polypath.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,11 @@ def relpath(path: str, start: str, alt_separator: str = "") -> str:

def commonpath(paths: list[str], alt_separator: str = "") -> str:
return posixpath.commonpath([normalize(path, alt_separator=alt_separator) for path in paths])


def isreserved(path: str) -> bool:
"""Return True if the path is a reserved name.
We currently do not have any reserved names.
"""
return False
27 changes: 24 additions & 3 deletions tests/helpers/test_fsutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,26 @@ def test_relpath(path: str, start: str, alt_separator: str, result: str) -> None
assert fsutil.relpath(path, start, alt_separator=alt_separator) == result


@pytest.mark.parametrize(
("paths, alt_separator, result"),
[
(["/some/dir/some/file", "/some/dir/some/other"], "", "/some/dir/some"),
(["/some/dir/some/file", "/some/dir/some/other"], "\\", "/some/dir/some"),
(["\\some\\dir\\some\\file", "\\some\\dir\\some\\other"], "\\", "/some/dir/some"),
(["/some/dir/some/file", "/some/dir/other"], "", "/some/dir"),
(["/some/dir/some/file", "/some/other"], "", "/some"),
(["/some/dir/some/file", "/some/other"], "\\", "/some"),
],
)
def test_commonpath(paths: list[str], alt_separator: str, result: str) -> None:
assert fsutil.commonpath(paths, alt_separator=alt_separator) == result


def test_isreserved() -> None:
assert not fsutil.isreserved("CON")
assert not fsutil.isreserved("foo")


def test_generate_addr() -> None:
slash_path = "/some/dir/some/file"
slash_vfs = VirtualFilesystem(alt_separator="")
Expand Down Expand Up @@ -312,9 +332,10 @@ def test_target_path_is_relative_to(path_fs: VirtualFilesystem) -> None:


def test_target_path_is_reserved(path_fs: VirtualFilesystem) -> None:
# We currently do not have any reserved names for TargetPath
assert not path_fs.path("CON").is_reserved()
assert not path_fs.path("foo").is_reserved()
if sys.version_info < (3, 13):
# We currently do not have any reserved names for TargetPath
assert not path_fs.path("CON").is_reserved()
assert not path_fs.path("foo").is_reserved()


def test_target_path_join(path_fs: VirtualFilesystem) -> None:
Expand Down

0 comments on commit b860576

Please sign in to comment.