The source project of this merge request has been removed.
Implement xattr attribute removal
As I wrote on GNOME Discourse, currently it is possible to set a xattr
attribute via GIO, but it is impossible to unset it.
For instance, PART 1
of the following code works and the attribute is created, but PART 2
fails and the attribute is not removed.
#include <glib.h>
#include <gio/gio.h>
#include <stdio.h>
#define G_FILE_ATTRIBUTE_XATTR_USER_CUSTOM "xattr::my_custom_attribute"
int main (int argc, char ** argv) {
GFile * location;
GError * err = NULL;
location = g_file_new_for_path("testfile.txt");
/* PART 1: Write "My custom content" into "user.my_custom_attribute" */
if (
!g_file_set_attribute_string(
location,
G_FILE_ATTRIBUTE_XATTR_USER_CUSTOM,
"My custom content",
G_FILE_QUERY_INFO_NONE,
NULL,
&err
)
) {
g_message(
"Sorry, something went wrong :-( // %s",
err->message
);
g_error_free(err);
g_object_unref(location);
return 1;
}
/* PART 2: Remove "user.my_custom_attribute" */
if (
!g_file_set_attribute(
location,
G_FILE_ATTRIBUTE_XATTR_USER_CUSTOM,
G_FILE_ATTRIBUTE_TYPE_INVALID,
NULL,
G_FILE_QUERY_INFO_NONE,
NULL,
&err
)
) {
g_message(
"Sorry, something went wrong :-( // %s",
err->message
);
g_error_free(err);
g_object_unref(location);
return 1;
}
g_object_unref(location);
return 0;
}
After searching a bit in the forum I found a similar question. Then I found out that a patch was proposed five years ago (#1187 (closed)), which idiomatically tried to implement G_FILE_ATTRIBUTE_TYPE_INVALID
for removing xattr
attributes. However after five years the patch cannot be merged anymore. So I tried to update it to the current version of GIO.
--madmurphy
Closes #1187 (closed)
Edited by Philip Withnall