GIO: Removing extended file attributes

I was trying to write and then remove a custom xattr attribute via GIO (user.my_custom_attribute), so I sketched the following code:

#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;

}

Unfortunately PART 1 of the code works and the attribute is created, but PART 2 fails and the attribute is not removed.

I searched a bit in the forum and I found a similar question. Then I found out that a patch was proposed five years ago, which would solve the issue (https://gitlab.gnome.org/GNOME/glib/-/issues/1187) – well, at least so it seems from the description (I did not look at the patch).

Are there any plans to support G_FILE_ATTRIBUTE_TYPE_INVALID for removing xattr attributes as per the patch above?

This should be solved now.

–madmurphy

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.