Skip to content

Commit

Permalink
include symlink destination in path info (#169)
Browse files Browse the repository at this point in the history
* Include symlink destination in path info.

The existing `parse_list_line_unix` function goes to all the work of parsing symlink lines, but omits the actual destination of the symlink. This tiny change adds parsed destination to the path's info dictionary.

* add tests for `link_dst` info key

---------

Co-authored-by: pohmelie <[email protected]>
  • Loading branch information
rcfox and pohmelie authored Dec 11, 2024
1 parent 8453684 commit 0dda701
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/aioftp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ def parse_list_line_unix(self, b):
link_src = s[:i]
i = -2 if link_dst[-1] == "'" or link_dst[-1] == '"' else -1
info["type"] = "dir" if link_dst[i] == "/" else "file"
info["link_dst"] = link_dst
s = link_src
return pathlib.PurePosixPath(s), info

Expand Down
8 changes: 8 additions & 0 deletions tests/test_simple_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ def test_parse_list_line_unix():
with pytest.raises(ValueError):
p(b"-rw-rw-r-- xx poh poh 6595 Feb 27 04:14 history.rst")

_, parsed = p(b"lrwxrwxrwx 1 poh poh 6 Mar 23 05:46 link-tmp.py -> tmp.py")
assert parsed["type"] == "file"
assert parsed["link_dst"] == "tmp.py"

_, parsed = p(b"lrwxrwxrwx 1 poh poh 6 Mar 23 05:46 link-tmp.py -> /tmp.py")
assert parsed["type"] == "file"
assert parsed["link_dst"] == "/tmp.py"


@pytest.mark.parametrize("owner", ["s", "x", "-", "E"])
@pytest.mark.parametrize("group", ["s", "x", "-", "E"])
Expand Down

0 comments on commit 0dda701

Please sign in to comment.