Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.0:Ports
gtk2
gtk2-updateiconcache_sort.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File gtk2-updateiconcache_sort.patch of Package gtk2
--- a/gtk/updateiconcache.c +++ b/gtk/updateiconcache.c @@ -37,6 +37,7 @@ #include <utime.h> #endif +#include <dirent.h> #include <glib.h> #include <glib/gstdio.h> #undef GDK_PIXBUF_DISABLE_DEPRECATED @@ -594,6 +595,50 @@ replace_backslashes_with_slashes (gchar path[i] = '/'; } +struct sortdir { + struct dirent **nl; + int cur; + int max; +}; + +static const gchar *sort_item(struct sortdir *sd) +{ + while (sd->cur >= 0) { + if (strcmp (sd->nl[sd->cur]->d_name, "..") == 0) + { + sd->cur--; + continue; + } + if (strcmp (sd->nl[sd->cur]->d_name, ".") == 0) + { + sd->cur--; + continue; + } + return sd->nl[sd->cur--]->d_name; + } + return NULL; +} + +static gboolean sort_open(char *path, struct sortdir *sd) +{ + int n; + + n = scandir(path, &sd->nl, NULL, alphasort); + if (n <= 0) + return FALSE; + sd->max = sd->cur = n - 1; + return TRUE; +} + +static void sort_close(struct sortdir *sd) +{ + int i; + + for (i = sd->max; i >= 0; i--) + free(sd->nl[i]); + free(sd->nl); +} + static GList * scan_directory (const gchar *base_path, const gchar *subdir, @@ -602,7 +647,7 @@ scan_directory (const gchar *base_path, gint depth) { GHashTable *dir_hash; - GDir *dir; + struct sortdir sortdir; const gchar *name; gchar *dir_path; gboolean dir_added = FALSE; @@ -610,15 +655,12 @@ scan_directory (const gchar *base_path, dir_path = g_build_path ("/", base_path, subdir, NULL); - /* FIXME: Use the gerror */ - dir = g_dir_open (dir_path, 0, NULL); - - if (!dir) + if (sort_open(dir_path, &sortdir) == FALSE) return directories; dir_hash = g_hash_table_new (g_str_hash, g_str_equal); - while ((name = g_dir_read_name (dir))) + while ((name = sort_item(&sortdir))) { gchar *path; gboolean retval; @@ -698,7 +740,7 @@ scan_directory (const gchar *base_path, g_free (path); } - g_dir_close (dir); + sort_close(&sortdir); /* Move dir into the big file hash */ g_hash_table_foreach_remove (dir_hash, foreach_remove_func, files);
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor