I’m trying to use some functions from the Gnome GIO library to get
extended file attributes. I’m doing this by writing a C extension
using the wonderful directions in
http://www.rubycentral.com/pickaxe/ext_ruby.html.
All that being said, I don’t really know Gnome or GTK+ at all, but I
thought my little code would be OK.
So I have the library built (rubygio.so) and the code all executes
fine. Problem is the gio api calls don’t return any info when I think
they should. I’m guessing there is some initialization stuff I’m
missing or maybe I have to have a window going or something. Any help
would be appreciated.
The C code to get the attributes looks like this:
static VALUE rbgio_load_attributes(VALUE self)
{
VALUE arr = rb_iv_get(self, “@attribute_array”);
VALUE names = rb_iv_get(self, “@name_array”);
VALUE path = rb_iv_get(self, “@path”);
GFile *ptr = g_file_new_for_path(STR2CSTR(path));
GError gerror = NULL;
GFileInfo finfo = g_file_query_info(ptr, "", 0, NULL, &gerror);
if (finfo == NULL) {
return INT2NUM(0);
}
char **attributes = g_file_info_list_attributes(finfo, "");
int i = 0;
while (attributes[i] != NULL) {
rb_ary_push(names, rb_str_new2(attributes[i]));
rb_ary_push(arr, rb_str_new2(g_file_info_get_attribute_as_string
(finfo, attributes[i])));
i++;
}
return INT2NUM(1)
}
Again it all runs (i’ve run it in gdb and examined variables). The
GFile ptr is a real address, the GFileInfo finfo is a real thing and
the char attributes is a valid list with no entries.
Any clues would be greatly appreciated. I will put the extension out
there once completed.
Mike