mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Handle xattr returning non-UTF-8 bytes.
This commit is contained in:
parent
a1274fc2dd
commit
6313682379
2 changed files with 16 additions and 0 deletions
|
@ -110,6 +110,9 @@ def read(path, attribute, **kwargs):
|
|||
|
||||
try:
|
||||
ret = salt.utils.mac_utils.execute_return_result(cmd)
|
||||
except UnicodeDecodeError as exc:
|
||||
# Mimic the builtin xattr tool by replacing undecodeable bytes.
|
||||
return exc.object.decode(errors="replace")
|
||||
except CommandExecutionError as exc:
|
||||
if "No such file" in exc.strerror:
|
||||
raise CommandExecutionError("File not found: {}".format(path))
|
||||
|
|
|
@ -74,6 +74,19 @@ def test_read_missing():
|
|||
pytest.raises(CommandExecutionError, xattr.read, "/path/to/file", "attribute")
|
||||
|
||||
|
||||
def test_read_not_decodeable():
|
||||
"""
|
||||
Test reading an attribute which returns non-UTF-8 bytes
|
||||
"""
|
||||
with patch(
|
||||
"salt.utils.mac_utils.execute_return_result",
|
||||
MagicMock(
|
||||
side_effect=UnicodeDecodeError("UTF-8", b"\xd1expected results", 0, 1, "")
|
||||
),
|
||||
):
|
||||
assert xattr.read("/path/to/file", "com.attr") == "<EFBFBD>expected results"
|
||||
|
||||
|
||||
def test_write():
|
||||
"""
|
||||
Test writing a specific attribute to a file
|
||||
|
|
Loading…
Add table
Reference in a new issue