]> Pileus Git - ~andy/gtk/blobdiff - gtk/updateiconcache.c
a11y: Emit text-changed signals directly
[~andy/gtk] / gtk / updateiconcache.c
index ea5cbfeb5a171bf12dfb62b3854d622b4e3e4db1..effea7c6c605611f497d77b8ec83f515001ab861 100644 (file)
@@ -12,9 +12,7 @@
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
@@ -73,11 +71,11 @@ static gchar *var_name = "-";
 
 #include <ftw.h>
 
-static struct stat cache_stat;
+static GStatBuf cache_stat;
 static gboolean cache_up_to_date;
 
 static int check_dir_mtime (const char        *dir, 
-                            const struct stat *sb,
+                            const GStatBuf    *sb,
                             int                tf)
 {
   if (tf != FTW_NS && sb->st_mtime > cache_stat.st_mtime)
@@ -90,9 +88,9 @@ static int check_dir_mtime (const char        *dir,
   return 0;
 }
 
- gboolean
- is_cache_up_to_date (const gchar *path)
- {
+static gboolean
+is_cache_up_to_date (const gchar *path)
+{
   gchar *cache_path;
   gint retval;
 
@@ -118,7 +116,7 @@ static int check_dir_mtime (const char        *dir,
 gboolean
 is_cache_up_to_date (const gchar *path)
 {
-  struct stat path_stat, cache_stat;
+  GStatBuf path_stat, cache_stat;
   gchar *cache_path;
   int retval; 
   
@@ -576,6 +574,23 @@ maybe_cache_icon_data (Image       *image,
     }
 }
 
+/**
+ * Finds all dir separators and replaces them with '/'.
+ * This makes sure that only /-separated paths are written in cache files,
+ * maintaining compatibility with theme index files that use slashes as
+ * directory separators on all platforms.
+ */
+static void
+replace_backslashes_with_slashes (gchar *path)
+{
+  size_t i;
+  if (path == NULL)
+    return;
+  for (i = 0; path[i]; i++)
+    if (G_IS_DIR_SEPARATOR (path[i]))
+      path[i] = '/';
+}
+
 static GList *
 scan_directory (const gchar *base_path, 
                const gchar *subdir, 
@@ -590,7 +605,7 @@ scan_directory (const gchar *base_path,
   gboolean dir_added = FALSE;
   guint dir_index = 0xffff;
   
-  dir_path = g_build_filename (base_path, subdir, NULL);
+  dir_path = g_build_path ("/", base_path, subdir, NULL);
 
   /* FIXME: Use the gerror */
   dir = g_dir_open (dir_path, 0, NULL);
@@ -609,13 +624,14 @@ scan_directory (const gchar *base_path,
       gchar *basename, *dot;
 
       path = g_build_filename (dir_path, name, NULL);
+
       retval = g_file_test (path, G_FILE_TEST_IS_DIR);
       if (retval)
        {
          gchar *subsubdir;
 
          if (subdir)
-           subsubdir = g_build_filename (subdir, name, NULL);
+           subsubdir = g_build_path ("/", subdir, name, NULL);
          else
            subsubdir = g_strdup (name);
          directories = scan_directory (base_path, subsubdir, files, 
@@ -1455,7 +1471,7 @@ build_cache (const gchar *path)
 #endif
   GHashTable *files;
   FILE *cache;
-  struct stat path_stat, cache_stat;
+  GStatBuf path_stat, cache_stat;
   struct utimbuf utime_buf;
   GList *directories = NULL;
   int fd;
@@ -1525,8 +1541,7 @@ opentmp:
     }
   cache = NULL;
 
-  g_list_foreach (directories, (GFunc)g_free, NULL);
-  g_list_free (directories);
+  g_list_free_full (directories, g_free);
 
   if (!validate_file (tmp_cache_path))
     {
@@ -1739,7 +1754,7 @@ main (int argc, char **argv)
   if (!force_update && is_cache_up_to_date (path))
     return 0;
 
-  g_type_init ();
+  replace_backslashes_with_slashes (path);
   build_cache (path);
 
   if (strcmp (var_name, "-") != 0)