mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-23 22:16:16 +01:00
gio-tool-info: Fix critical warning when --attributes are specified
When `--attributes` is specified and doesn’t include `standard::name` in its list, `gio` would print a critical warning from the (mandatory) call to `g_file_info_get_name()`. Fix that by making the call to `g_file_info_get_name()` optional. Add a unit test too. Signed-off-by: Philip Withnall <philip@tecnocode.co.uk> Fixes: #3158
This commit is contained in:
parent
3e0a99a059
commit
9028c9bdf3
@ -177,7 +177,8 @@ show_info (GFile *file, GFileInfo *info)
|
||||
g_free (flatten);
|
||||
}
|
||||
|
||||
name = g_file_info_get_name (info);
|
||||
name = g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_NAME) ?
|
||||
g_file_info_get_name (info) : NULL;
|
||||
if (name)
|
||||
{
|
||||
escaped = escape_string (name);
|
||||
|
@ -119,6 +119,14 @@ class TestGioTool(unittest.TestCase):
|
||||
with self.assertRaises(subprocess.CalledProcessError):
|
||||
self.runGio()
|
||||
|
||||
def test_info_non_default_attributes(self):
|
||||
"""Test running `gio info --attributes` with a non-default list."""
|
||||
with tempfile.NamedTemporaryFile(dir=self.tmpdir.name) as tmpfile:
|
||||
result = self.runGio(
|
||||
"info", "--attributes=standard::content-type", tmpfile.name
|
||||
)
|
||||
self.assertIn("standard::content-type: application/x-zerosize", result.out)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(testRunner=taptestrunner.TAPTestRunner())
|
||||
|
Loading…
Reference in New Issue
Block a user