g_file_enumerate_children() fails to return all items when run as root
Submitted by Emil Brink
Link to original bug (#632129)
Description
Hi!
The following test program:
/*
- Compile with:
- gcc $(pkg-config --cflags gio-2.0) -o giotest giotest.c $(pkg-config --libs gio-2.0) */
#include <stdio.h> #include <stdlib.h>
#include <gio/gio.h>
static void list_files(GVfs *vfs, const char *path, GError **err) { GFile *here; GFileEnumerator *fe;
if((here = g_vfs_parse_name(vfs, path)) == NULL)
{
fprintf(stderr, "**Failed to parse \"%s\" as name\n", path);
return;
}
if((fe = g_file_enumerate_children(here, "standard::*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, err)) != NULL)
{
GFileInfo *fi;
while((fi = g_file_enumerator_next_file(fe, NULL, err)) != NULL)
{
const gchar *name = g_file_info_get_name(fi);
printf("%s\n", name);
g_object_unref(G_OBJECT(fi));
}
g_object_unref(fe);
}
}
int main(int argc, char *argv[]) { GVfs *vfs; int i;
g_type_init();
g_thread_init(NULL);
if((vfs = g_vfs_get_default()) == NULL)
{
fprintf(stderr, "**No GVFs, aborting\n");
return EXIT_FAILURE;
}
for(i = 1; argv[i] != NULL; i++)
{
GError *err = NULL;
printf("%s:\n", argv[i]);
list_files(vfs, argv[i], &err);
}
return EXIT_SUCCESS;
}
shows a different set of files when listing e.g. my home directory when run as root, as compared to when its run by myself. I think this is very odd; listing files as root should never show fewer than a regular user account shows for the same path.
I tried with both "standard::" and just plain "" for the attributes, it doesn't seem to make a difference.
I made this severity major, since it's quite disabling for some classes of applications that are occasionally used by root to e.g. look for files.
I noticed that gnomevfs-ls does not suffer from this problem, so I guess there's an issue with how I use the API:s, but I don't understand what's wrong with the above.