diff --git a/docs/reference/gio/gio-sections-common.txt b/docs/reference/gio/gio-sections-common.txt index f0d1c713d..43da80c50 100644 --- a/docs/reference/gio/gio-sections-common.txt +++ b/docs/reference/gio/gio-sections-common.txt @@ -391,6 +391,7 @@ g_file_info_get_attribute_status g_file_info_get_attribute_string g_file_info_get_attribute_stringv g_file_info_get_attribute_byte_string +g_file_info_get_attribute_file_path g_file_info_get_attribute_boolean g_file_info_get_attribute_uint32 g_file_info_get_attribute_int32 @@ -402,6 +403,7 @@ g_file_info_set_attribute_status g_file_info_set_attribute_string g_file_info_set_attribute_stringv g_file_info_set_attribute_byte_string +g_file_info_set_attribute_file_path g_file_info_set_attribute_boolean g_file_info_set_attribute_uint32 g_file_info_set_attribute_int32 diff --git a/gio/gfileinfo.c b/gio/gfileinfo.c index 3b34bd4d4..af7828ee6 100644 --- a/gio/gfileinfo.c +++ b/gio/gfileinfo.c @@ -966,6 +966,30 @@ g_file_info_get_attribute_byte_string (GFileInfo *info, return _g_file_attribute_value_get_byte_string (value); } +/** + * g_file_info_get_attribute_file_path: + * @info: a #GFileInfo. + * @attribute: a file attribute key. + * + * Gets the value of a byte string attribute as a file path. + * + * If the attribute does not contain a byte string, `NULL` will be returned. + * + * This function is meant to be used by language bindings that have specific + * handling for Unix paths. + * + * Returns: (type filename) (nullable): the contents of the @attribute value as + * a file path, or %NULL otherwise. + * + * Since: 2.78 + **/ +const char * +g_file_info_get_attribute_file_path (GFileInfo *info, + const char *attribute) +{ + return g_file_info_get_attribute_byte_string (info, attribute); +} + /** * g_file_info_get_attribute_stringv: * @info: a #GFileInfo. @@ -1318,6 +1342,28 @@ g_file_info_set_attribute_byte_string (GFileInfo *info, attr_value); } +/** + * g_file_info_set_attribute_file_path: + * @info: a #GFileInfo. + * @attribute: a file attribute key. + * @attr_value: (type filename): a file path. + * + * Sets the @attribute to contain the given @attr_value, + * if possible. + * + * This function is meant to be used by language bindings that have specific + * handling for Unix paths. + * + * Since: 2.78 + **/ +void +g_file_info_set_attribute_file_path (GFileInfo *info, + const char *attribute, + const char *attr_value) +{ + g_file_info_set_attribute_byte_string (info, attribute, attr_value); +} + void _g_file_info_set_attribute_boolean_by_id (GFileInfo *info, guint32 attribute, diff --git a/gio/gfileinfo.h b/gio/gfileinfo.h index 11ad4710c..95207b80b 100644 --- a/gio/gfileinfo.h +++ b/gio/gfileinfo.h @@ -1360,6 +1360,9 @@ GObject * g_file_info_get_attribute_object (GFileInfo *info, GIO_AVAILABLE_IN_ALL char ** g_file_info_get_attribute_stringv (GFileInfo *info, const char *attribute); +GIO_AVAILABLE_IN_2_78 +const char * g_file_info_get_attribute_file_path (GFileInfo *info, + const char *attribute); GIO_AVAILABLE_IN_ALL void g_file_info_set_attribute (GFileInfo *info, @@ -1402,6 +1405,10 @@ GIO_AVAILABLE_IN_ALL void g_file_info_set_attribute_stringv (GFileInfo *info, const char *attribute, char **attr_value); +GIO_AVAILABLE_IN_2_78 +void g_file_info_set_attribute_file_path (GFileInfo *info, + const char *attribute, + const char *attr_value); GIO_AVAILABLE_IN_ALL void g_file_info_clear_status (GFileInfo *info); diff --git a/gio/tests/g-file-info.c b/gio/tests/g-file-info.c index f19271c64..9b4c6368c 100644 --- a/gio/tests/g-file-info.c +++ b/gio/tests/g-file-info.c @@ -43,7 +43,7 @@ static void test_assigned_values (GFileInfo *info) { - const char *name, *display_name, *mistake; + const char *name, *name_filepath, *display_name, *mistake; guint64 size; GFileType type; @@ -56,12 +56,14 @@ test_assigned_values (GFileInfo *info) /* Retrieve data back and compare */ name = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_STANDARD_NAME); + name_filepath = g_file_info_get_attribute_file_path (info, G_FILE_ATTRIBUTE_STANDARD_NAME); display_name = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME); mistake = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_COPY_NAME); size = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_SIZE); type = g_file_info_get_file_type (info); g_assert_cmpstr (name, ==, TEST_NAME); + g_assert_cmpstr (name_filepath, ==, name); g_assert_cmpstr (display_name, ==, TEST_DISPLAY_NAME); g_assert_null (mistake); g_assert_cmpint (size, ==, TEST_SIZE); @@ -102,7 +104,12 @@ test_g_file_info (void) g_strfreev (attr_list); test_assigned_values (info); - + + /* Test the file path encoding functions */ + g_file_info_set_attribute_file_path (info, G_FILE_ATTRIBUTE_STANDARD_NAME, "something different"); + g_assert_cmpstr (g_file_info_get_attribute_file_path (info, G_FILE_ATTRIBUTE_STANDARD_NAME), ==, "something different"); + g_file_info_set_attribute_file_path (info, G_FILE_ATTRIBUTE_STANDARD_NAME, TEST_NAME); + /* Test dups */ info_dup = g_file_info_dup (info); g_assert_nonnull (info_dup);