]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfilesystemunix.c
Revert the patch to #137520, as 2.4.1 is for conservative bug fixes only.
[~andy/gtk] / gtk / gtkfilesystemunix.c
index f62f44e1c57e686b10ba096648a186dac6a286ac..01528ce533e9b2a8c7b5493f4719e11483370ff6 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
+#include <config.h>
+
 #include "gtkfilesystem.h"
 #include "gtkfilesystemunix.h"
+#include "gtkicontheme.h"
+#include "gtkintl.h"
 
+#define XDG_PREFIX _gtk_xdg
 #include "xdgmime/xdgmime.h"
 
 #include <errno.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <stdio.h>
+#include <time.h>
+
+#define BOOKMARKS_FILENAME ".gtk-bookmarks"
+#define BOOKMARKS_TMP_FILENAME ".gtk-bookmarks-XXXXXX"
+
+#define FOLDER_CACHE_LIFETIME 2 /* seconds */
 
 typedef struct _GtkFileSystemUnixClass GtkFileSystemUnixClass;
 
@@ -43,8 +55,26 @@ struct _GtkFileSystemUnixClass
 struct _GtkFileSystemUnix
 {
   GObject parent_instance;
+
+  GHashTable *folder_hash;
 };
 
+/* Icon type, supplemented by MIME type
+ */
+typedef enum {
+  ICON_UNDECIDED,
+  ICON_NONE,
+  ICON_REGULAR,        /* Use mime type for icon */
+  ICON_BLOCK_DEVICE,
+  ICON_BROKEN_SYMBOLIC_LINK,
+  ICON_CHARACTER_DEVICE,
+  ICON_DIRECTORY,
+  ICON_EXECUTABLE,
+  ICON_FIFO,
+  ICON_SOCKET
+} IconType;
+
+
 #define GTK_TYPE_FILE_FOLDER_UNIX             (gtk_file_folder_unix_get_type ())
 #define GTK_FILE_FOLDER_UNIX(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_FOLDER_UNIX, GtkFileFolderUnix))
 #define GTK_IS_FILE_FOLDER_UNIX(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_FOLDER_UNIX))
@@ -64,10 +94,26 @@ struct _GtkFileFolderUnix
 {
   GObject parent_instance;
 
+  GtkFileSystemUnix *system_unix;
   GtkFileInfoType types;
   gchar *filename;
+  GHashTable *stat_info;
+  unsigned int have_stat : 1;
+  unsigned int have_mime_type : 1;
+  time_t asof;
+};
+
+struct stat_info_entry {
+  struct stat statbuf;
+  char *mime_type;
+  IconType icon_type;
 };
 
+static const GtkFileInfoType STAT_NEEDED_MASK = (GTK_FILE_INFO_IS_FOLDER |
+                                                GTK_FILE_INFO_IS_HIDDEN |
+                                                GTK_FILE_INFO_MODIFICATION_TIME |
+                                                GTK_FILE_INFO_SIZE);
+
 static GObjectClass *system_parent_class;
 static GObjectClass *folder_parent_class;
 
@@ -76,11 +122,10 @@ static void gtk_file_system_unix_iface_init   (GtkFileSystemIface     *iface);
 static void gtk_file_system_unix_init         (GtkFileSystemUnix      *impl);
 static void gtk_file_system_unix_finalize     (GObject                *object);
 
-static GSList *       gtk_file_system_unix_list_roots    (GtkFileSystem      *file_system);
-static GtkFileInfo *  gtk_file_system_unix_get_root_info (GtkFileSystem      *file_system,
-                                                         const GtkFilePath  *path,
-                                                         GtkFileInfoType     types,
-                                                         GError            **error);
+static GSList *             gtk_file_system_unix_list_volumes        (GtkFileSystem     *file_system);
+static GtkFileSystemVolume *gtk_file_system_unix_get_volume_for_path (GtkFileSystem     *file_system,
+                                                                     const GtkFilePath *path);
+
 static GtkFileFolder *gtk_file_system_unix_get_folder    (GtkFileSystem      *file_system,
                                                          const GtkFilePath  *path,
                                                          GtkFileInfoType     types,
@@ -88,6 +133,24 @@ static GtkFileFolder *gtk_file_system_unix_get_folder    (GtkFileSystem      *fi
 static gboolean       gtk_file_system_unix_create_folder (GtkFileSystem      *file_system,
                                                          const GtkFilePath  *path,
                                                          GError            **error);
+
+static void         gtk_file_system_unix_volume_free             (GtkFileSystem       *file_system,
+                                                                 GtkFileSystemVolume *volume);
+static GtkFilePath *gtk_file_system_unix_volume_get_base_path    (GtkFileSystem       *file_system,
+                                                                 GtkFileSystemVolume *volume);
+static gboolean     gtk_file_system_unix_volume_get_is_mounted   (GtkFileSystem       *file_system,
+                                                                 GtkFileSystemVolume *volume);
+static gboolean     gtk_file_system_unix_volume_mount            (GtkFileSystem       *file_system,
+                                                                 GtkFileSystemVolume *volume,
+                                                                 GError             **error);
+static gchar *      gtk_file_system_unix_volume_get_display_name (GtkFileSystem       *file_system,
+                                                                 GtkFileSystemVolume *volume);
+static GdkPixbuf *  gtk_file_system_unix_volume_render_icon      (GtkFileSystem        *file_system,
+                                                                 GtkFileSystemVolume  *volume,
+                                                                 GtkWidget            *widget,
+                                                                 gint                  pixel_size,
+                                                                 GError              **error);
+
 static gboolean       gtk_file_system_unix_get_parent    (GtkFileSystem      *file_system,
                                                          const GtkFilePath  *path,
                                                          GtkFilePath       **parent,
@@ -112,11 +175,20 @@ static GtkFilePath *gtk_file_system_unix_uri_to_path      (GtkFileSystem     *fi
 static GtkFilePath *gtk_file_system_unix_filename_to_path (GtkFileSystem     *file_system,
                                                           const gchar       *filename);
 
-static gboolean       gtk_file_system_unix_get_supports_bookmarks (GtkFileSystem *file_system);
-static void           gtk_file_system_unix_set_bookmarks          (GtkFileSystem *file_system,
-                                                                  GSList        *bookmarks,
-                                                                  GError       **error);
-static GSList *       gtk_file_system_unix_list_bookmarks         (GtkFileSystem *file_system);
+static GdkPixbuf *gtk_file_system_unix_render_icon (GtkFileSystem     *file_system,
+                                                   const GtkFilePath *path,
+                                                   GtkWidget         *widget,
+                                                   gint               pixel_size,
+                                                   GError           **error);
+
+static gboolean gtk_file_system_unix_insert_bookmark (GtkFileSystem     *file_system,
+                                                     const GtkFilePath *path,
+                                                     gint               position,
+                                                     GError           **error);
+static gboolean gtk_file_system_unix_remove_bookmark (GtkFileSystem     *file_system,
+                                                     const GtkFilePath *path,
+                                                     GError           **error);
+static GSList * gtk_file_system_unix_list_bookmarks  (GtkFileSystem *file_system);
 
 static GType gtk_file_folder_unix_get_type   (void);
 static void  gtk_file_folder_unix_class_init (GtkFileFolderUnixClass *class);
@@ -131,13 +203,15 @@ static gboolean     gtk_file_folder_unix_list_children (GtkFileFolder  *folder,
                                                        GSList        **children,
                                                        GError        **error);
 
-static gchar *      filename_from_path (const GtkFilePath *path);
 static GtkFilePath *filename_to_path   (const gchar       *filename);
 
 static gboolean     filename_is_root  (const char       *filename);
-static GtkFileInfo *filename_get_info (const gchar      *filename,
-                                      GtkFileInfoType   types,
-                                      GError          **error);
+
+static gboolean fill_in_names (GtkFileFolderUnix *folder_unix, GError **error);
+static gboolean fill_in_stats (GtkFileFolderUnix *folder_unix, GError **error);
+static gboolean fill_in_mime_type (GtkFileFolderUnix *folder_unix, GError **error);
+
+static char *       get_parent_dir    (const char       *filename);
 
 /*
  * GtkFileSystemUnix
@@ -161,7 +235,7 @@ gtk_file_system_unix_get_type (void)
        0,              /* n_preallocs */
        (GInstanceInitFunc) gtk_file_system_unix_init,
       };
-      
+
       static const GInterfaceInfo file_system_info =
       {
        (GInterfaceInitFunc) gtk_file_system_unix_iface_init, /* interface_init */
@@ -182,11 +256,11 @@ gtk_file_system_unix_get_type (void)
 
 /**
  * gtk_file_system_unix_new:
- * 
+ *
  * Creates a new #GtkFileSystemUnix object. #GtkFileSystemUnix
  * implements the #GtkFileSystem interface with direct access to
  * the filesystem using Unix/Linux API calls
- * 
+ *
  * Return value: the new #GtkFileSystemUnix object
  **/
 GtkFileSystem *
@@ -201,17 +275,23 @@ gtk_file_system_unix_class_init (GtkFileSystemUnixClass *class)
   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
 
   system_parent_class = g_type_class_peek_parent (class);
-  
+
   gobject_class->finalize = gtk_file_system_unix_finalize;
 }
 
 static void
 gtk_file_system_unix_iface_init   (GtkFileSystemIface *iface)
 {
-  iface->list_roots = gtk_file_system_unix_list_roots;
+  iface->list_volumes = gtk_file_system_unix_list_volumes;
+  iface->get_volume_for_path = gtk_file_system_unix_get_volume_for_path;
   iface->get_folder = gtk_file_system_unix_get_folder;
-  iface->get_root_info = gtk_file_system_unix_get_root_info;
   iface->create_folder = gtk_file_system_unix_create_folder;
+  iface->volume_free = gtk_file_system_unix_volume_free;
+  iface->volume_get_base_path = gtk_file_system_unix_volume_get_base_path;
+  iface->volume_get_is_mounted = gtk_file_system_unix_volume_get_is_mounted;
+  iface->volume_mount = gtk_file_system_unix_volume_mount;
+  iface->volume_get_display_name = gtk_file_system_unix_volume_get_display_name;
+  iface->volume_render_icon = gtk_file_system_unix_volume_render_icon;
   iface->get_parent = gtk_file_system_unix_get_parent;
   iface->make_path = gtk_file_system_unix_make_path;
   iface->parse = gtk_file_system_unix_parse;
@@ -219,39 +299,62 @@ gtk_file_system_unix_iface_init   (GtkFileSystemIface *iface)
   iface->path_to_filename = gtk_file_system_unix_path_to_filename;
   iface->uri_to_path = gtk_file_system_unix_uri_to_path;
   iface->filename_to_path = gtk_file_system_unix_filename_to_path;
-  iface->get_supports_bookmarks = gtk_file_system_unix_get_supports_bookmarks;
-  iface->set_bookmarks = gtk_file_system_unix_set_bookmarks;
+  iface->render_icon = gtk_file_system_unix_render_icon;
+  iface->insert_bookmark = gtk_file_system_unix_insert_bookmark;
+  iface->remove_bookmark = gtk_file_system_unix_remove_bookmark;
   iface->list_bookmarks = gtk_file_system_unix_list_bookmarks;
 }
 
 static void
 gtk_file_system_unix_init (GtkFileSystemUnix *system_unix)
 {
+  system_unix->folder_hash = g_hash_table_new (g_str_hash, g_str_equal);
 }
 
 static void
 gtk_file_system_unix_finalize (GObject *object)
 {
+  GtkFileSystemUnix *system_unix;
+
+  system_unix = GTK_FILE_SYSTEM_UNIX (object);
+
+  /* FIXME: assert that the hash is empty? */
+  g_hash_table_destroy (system_unix->folder_hash);
+
   system_parent_class->finalize (object);
 }
 
+/* Returns our single root volume */
+static GtkFileSystemVolume *
+get_root_volume (void)
+{
+  return (GtkFileSystemVolume *) gtk_file_path_new_dup ("/");
+}
+
 static GSList *
-gtk_file_system_unix_list_roots (GtkFileSystem *file_system)
+gtk_file_system_unix_list_volumes (GtkFileSystem *file_system)
 {
-  return g_slist_append (NULL, gtk_file_path_new_dup ("/"));
+  return g_slist_append (NULL, get_root_volume ());
 }
 
-static GtkFileInfo *
-gtk_file_system_unix_get_root_info (GtkFileSystem    *file_system,
-                                   const GtkFilePath      *path,
-                                   GtkFileInfoType   types,
-                                   GError          **error)
+static GtkFileSystemVolume *
+gtk_file_system_unix_get_volume_for_path (GtkFileSystem     *file_system,
+                                         const GtkFilePath *path)
+{
+  return get_root_volume ();
+}
+
+static char *
+remove_trailing_slash (const char *filename)
 {
-  const gchar *filename = gtk_file_path_get_string (path);
-  
-  g_return_val_if_fail (strcmp (filename, "/") == 0, NULL);
+  int len;
 
-  return filename_get_info ("/", types, error);
+  len = strlen (filename);
+
+  if (len > 1 && filename[len - 1] == '/')
+    return g_strndup (filename, len - 1);
+  else
+    return g_memdup (filename, len + 1);
 }
 
 static GtkFileFolder *
@@ -260,15 +363,95 @@ gtk_file_system_unix_get_folder (GtkFileSystem     *file_system,
                                 GtkFileInfoType    types,
                                 GError           **error)
 {
+  GtkFileSystemUnix *system_unix;
   GtkFileFolderUnix *folder_unix;
-  gchar *filename;
+  const char *filename;
+  char *filename_copy;
+  time_t now = time (NULL);
+
+  system_unix = GTK_FILE_SYSTEM_UNIX (file_system);
 
-  filename = filename_from_path (path);
+  filename = gtk_file_path_get_string (path);
   g_return_val_if_fail (filename != NULL, NULL);
+  g_return_val_if_fail (g_path_is_absolute (filename), NULL);
 
-  folder_unix = g_object_new (GTK_TYPE_FILE_FOLDER_UNIX, NULL);
-  folder_unix->filename = filename;
-  folder_unix->types = types;
+  filename_copy = remove_trailing_slash (filename);
+  folder_unix = g_hash_table_lookup (system_unix->folder_hash, filename_copy);
+
+  if (folder_unix)
+    {
+      g_free (filename_copy);
+      if (now - folder_unix->asof >= FOLDER_CACHE_LIFETIME &&
+         folder_unix->stat_info)
+       {
+#if 0
+         g_print ("Cleaning out cached directory %s\n", filename);
+#endif
+         g_hash_table_destroy (folder_unix->stat_info);
+         folder_unix->stat_info = NULL;
+         folder_unix->have_mime_type = FALSE;
+         folder_unix->have_stat = FALSE;
+       }
+
+      g_object_ref (folder_unix);
+      folder_unix->types |= types;
+      types = folder_unix->types;
+    }
+  else
+    {
+      if (!g_file_test (filename, G_FILE_TEST_IS_DIR))
+       {
+         int save_errno = errno;
+         gchar *filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
+
+         /* If g_file_test() returned FALSE but not due to an error, it means
+          * that the filename is not a directory.
+          */
+         if (save_errno == 0)
+           /* ENOTDIR */
+           g_set_error (error,
+                        GTK_FILE_SYSTEM_ERROR,
+                        GTK_FILE_SYSTEM_ERROR_NOT_FOLDER,
+                        _("%s: %s"),
+                        filename_utf8 ? filename_utf8 : "???",
+                        g_strerror (ENOTDIR));
+         else
+           g_set_error (error,
+                        GTK_FILE_SYSTEM_ERROR,
+                        GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
+                        _("error getting information for '%s': %s"),
+                        filename_utf8 ? filename_utf8 : "???",
+                        g_strerror (save_errno));
+
+         g_free (filename_utf8);
+         g_free (filename_copy);
+         return NULL;
+       }
+
+      folder_unix = g_object_new (GTK_TYPE_FILE_FOLDER_UNIX, NULL);
+      folder_unix->system_unix = system_unix;
+      folder_unix->filename = filename_copy;
+      folder_unix->types = types;
+      folder_unix->stat_info = NULL;
+      folder_unix->asof = now;
+      folder_unix->have_mime_type = FALSE;
+      folder_unix->have_stat = FALSE;
+
+      g_hash_table_insert (system_unix->folder_hash,
+                          folder_unix->filename,
+                          folder_unix);
+    }
+
+  if ((types & STAT_NEEDED_MASK) && !fill_in_stats (folder_unix, error))
+    {
+      g_object_unref (folder_unix);
+      return NULL;
+    }
+  if ((types & GTK_FILE_INFO_MIME_TYPE) && !fill_in_mime_type (folder_unix, error))
+    {
+      g_object_unref (folder_unix);
+      return NULL;
+    }
 
   return GTK_FILE_FOLDER (folder_unix);
 }
@@ -278,29 +461,268 @@ gtk_file_system_unix_create_folder (GtkFileSystem     *file_system,
                                    const GtkFilePath *path,
                                    GError           **error)
 {
-  gchar *filename;
+  GtkFileSystemUnix *system_unix;
+  const char *filename;
   gboolean result;
+  char *parent, *tmp;
+
+  system_unix = GTK_FILE_SYSTEM_UNIX (file_system);
 
-  filename = filename_from_path (path);
+  filename = gtk_file_path_get_string (path);
   g_return_val_if_fail (filename != NULL, FALSE);
-  
-  result = mkdir (filename, 0777) != 0;
-  
+  g_return_val_if_fail (g_path_is_absolute (filename), FALSE);
+
+  tmp = remove_trailing_slash (filename);
+  result = mkdir (tmp, 0777) == 0;
+  g_free (tmp);
+
   if (!result)
     {
+      int save_errno = errno;
       gchar *filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
       g_set_error (error,
                   GTK_FILE_SYSTEM_ERROR,
                   GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
-                  "error creating directory '%s': %s",
+                  _("error creating directory '%s': %s"),
                   filename_utf8 ? filename_utf8 : "???",
-                  g_strerror (errno));
+                  g_strerror (save_errno));
       g_free (filename_utf8);
+      return FALSE;
     }
-  
-  g_free (filename);
-  
-  return result;
+
+  if (filename_is_root (filename))
+    return TRUE; /* hmmm, but with no notification */
+
+  parent = get_parent_dir (filename);
+  if (parent)
+    {
+      GtkFileFolderUnix *folder_unix;
+
+      folder_unix = g_hash_table_lookup (system_unix->folder_hash, parent);
+      if (folder_unix)
+       {
+         GtkFileInfoType types;
+         GtkFilePath *parent_path;
+         GSList *paths;
+         GtkFileFolder *folder;
+
+         /* This is sort of a hack.  We re-get the folder, to ensure that the
+          * newly-created directory gets read into the folder's info hash table.
+          */
+
+         types = folder_unix->types;
+
+         parent_path = gtk_file_path_new_dup (parent);
+         folder = gtk_file_system_get_folder (file_system, parent_path, types, NULL);
+         gtk_file_path_free (parent_path);
+
+         if (folder)
+           {
+             paths = g_slist_append (NULL, (GtkFilePath *) path);
+             g_signal_emit_by_name (folder, "files-added", paths);
+             g_slist_free (paths);
+             g_object_unref (folder);
+           }
+       }
+
+      g_free (parent);
+    }
+
+  return TRUE;
+}
+
+static void
+gtk_file_system_unix_volume_free (GtkFileSystem        *file_system,
+                                 GtkFileSystemVolume  *volume)
+{
+  GtkFilePath *path;
+
+  path = (GtkFilePath *) volume;
+  gtk_file_path_free (path);
+}
+
+static GtkFilePath *
+gtk_file_system_unix_volume_get_base_path (GtkFileSystem        *file_system,
+                                          GtkFileSystemVolume  *volume)
+{
+  return gtk_file_path_new_dup ("/");
+}
+
+static gboolean
+gtk_file_system_unix_volume_get_is_mounted (GtkFileSystem        *file_system,
+                                           GtkFileSystemVolume  *volume)
+{
+  return TRUE;
+}
+
+static gboolean
+gtk_file_system_unix_volume_mount (GtkFileSystem        *file_system,
+                                  GtkFileSystemVolume  *volume,
+                                  GError              **error)
+{
+  g_set_error (error,
+              GTK_FILE_SYSTEM_ERROR,
+              GTK_FILE_SYSTEM_ERROR_FAILED,
+              _("This file system does not support mounting"));
+  return FALSE;
+}
+
+static gchar *
+gtk_file_system_unix_volume_get_display_name (GtkFileSystem       *file_system,
+                                             GtkFileSystemVolume *volume)
+{
+  return g_strdup (_("Filesystem")); /* Same as Nautilus */
+}
+
+static IconType
+get_icon_type_from_stat (struct stat *statp)
+{
+  if (S_ISBLK (statp->st_mode))
+    return ICON_BLOCK_DEVICE;
+  else if (S_ISLNK (statp->st_mode))
+    return ICON_BROKEN_SYMBOLIC_LINK; /* See get_icon_type */
+  else if (S_ISCHR (statp->st_mode))
+    return ICON_CHARACTER_DEVICE;
+  else if (S_ISDIR (statp->st_mode))
+    return ICON_DIRECTORY;
+  else if (S_ISFIFO (statp->st_mode))
+    return  ICON_FIFO;
+  else if (S_ISSOCK (statp->st_mode))
+    return ICON_SOCKET;
+  else
+    return ICON_REGULAR;
+}
+
+static IconType
+get_icon_type (const char *filename,
+              GError    **error)
+{
+  struct stat statbuf;
+
+  /* If stat fails, try to fall back to lstat to catch broken links
+   */
+  if (stat (filename, &statbuf) != 0)
+    {
+      if (errno != ENOENT || lstat (filename, &statbuf) != 0)
+       {
+         int save_errno = errno;
+         gchar *filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
+         g_set_error (error,
+                      GTK_FILE_SYSTEM_ERROR,
+                      GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
+                      _("error getting information for '%s': %s"),
+                      filename_utf8 ? filename_utf8 : "???",
+                      g_strerror (save_errno));
+         g_free (filename_utf8);
+
+         return ICON_NONE;
+       }
+    }
+
+  return get_icon_type_from_stat (&statbuf);
+}
+
+typedef struct
+{
+  gint size;
+  GdkPixbuf *pixbuf;
+} IconCacheElement;
+
+static void
+icon_cache_element_free (IconCacheElement *element)
+{
+  if (element->pixbuf)
+    g_object_unref (element->pixbuf);
+  g_free (element);
+}
+
+static void
+icon_theme_changed (GtkIconTheme *icon_theme)
+{
+  GHashTable *cache;
+
+  /* Difference from the initial creation is that we don't
+   * reconnect the signal
+   */
+  cache = g_hash_table_new_full (g_str_hash, g_str_equal,
+                                (GDestroyNotify)g_free,
+                                (GDestroyNotify)icon_cache_element_free);
+  g_object_set_data_full (G_OBJECT (icon_theme), "gtk-file-icon-cache",
+                         cache, (GDestroyNotify)g_hash_table_destroy);
+}
+
+static GdkPixbuf *
+get_cached_icon (GtkWidget   *widget,
+                const gchar *name,
+                gint         pixel_size)
+{
+  GtkIconTheme *icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
+  GHashTable *cache = g_object_get_data (G_OBJECT (icon_theme), "gtk-file-icon-cache");
+  IconCacheElement *element;
+
+  if (!cache)
+    {
+      cache = g_hash_table_new_full (g_str_hash, g_str_equal,
+                                    (GDestroyNotify)g_free,
+                                    (GDestroyNotify)icon_cache_element_free);
+
+      g_object_set_data_full (G_OBJECT (icon_theme), "gtk-file-icon-cache",
+                             cache, (GDestroyNotify)g_hash_table_destroy);
+      g_signal_connect (icon_theme, "changed",
+                       G_CALLBACK (icon_theme_changed), NULL);
+    }
+
+  element = g_hash_table_lookup (cache, name);
+  if (!element)
+    {
+      element = g_new0 (IconCacheElement, 1);
+      g_hash_table_insert (cache, g_strdup (name), element);
+    }
+
+  if (element->size != pixel_size)
+    {
+      if (element->pixbuf)
+       g_object_unref (element->pixbuf);
+      element->size = pixel_size;
+      element->pixbuf = gtk_icon_theme_load_icon (icon_theme, name,
+                                                 pixel_size, 0, NULL);
+    }
+
+  return element->pixbuf ? g_object_ref (element->pixbuf) : NULL;
+}
+
+static GdkPixbuf *
+gtk_file_system_unix_volume_render_icon (GtkFileSystem        *file_system,
+                                        GtkFileSystemVolume  *volume,
+                                        GtkWidget            *widget,
+                                        gint                  pixel_size,
+                                        GError              **error)
+{
+  /* FIXME: set the GError if we can't load the icon */
+  return get_cached_icon (widget, "gnome-fs-blockdev", pixel_size);
+}
+
+static char *
+get_parent_dir (const char *filename)
+{
+  int len;
+
+  len = strlen (filename);
+
+  /* Ignore trailing slashes */
+  if (len > 1 && filename[len - 1] == '/')
+    {
+      char *tmp, *parent;
+
+      tmp = g_strndup (filename, len - 1);
+
+      parent = g_path_get_dirname (tmp);
+      g_free (tmp);
+
+      return parent;
+    }
+  else
+    return g_path_get_dirname (filename);
 }
 
 static gboolean
@@ -309,8 +731,11 @@ gtk_file_system_unix_get_parent (GtkFileSystem     *file_system,
                                 GtkFilePath      **parent,
                                 GError           **error)
 {
-  gchar *filename = filename_from_path (path);
+  const char *filename;
+
+  filename = gtk_file_path_get_string (path);
   g_return_val_if_fail (filename != NULL, FALSE);
+  g_return_val_if_fail (g_path_is_absolute (filename), FALSE);
 
   if (filename_is_root (filename))
     {
@@ -318,13 +743,11 @@ gtk_file_system_unix_get_parent (GtkFileSystem     *file_system,
     }
   else
     {
-      gchar *parent_filename = g_path_get_dirname (filename);
+      gchar *parent_filename = get_parent_dir (filename);
       *parent = filename_to_path (parent_filename);
       g_free (parent_filename);
     }
 
-  g_free (filename);
-
   return TRUE;
 }
 
@@ -334,14 +757,15 @@ gtk_file_system_unix_make_path (GtkFileSystem    *file_system,
                               const gchar       *display_name,
                               GError           **error)
 {
-  gchar *base_filename;
+  const char *base_filename;
   gchar *filename;
   gchar *full_filename;
   GError *tmp_error = NULL;
   GtkFilePath *result;
-  
-  base_filename = filename_from_path (base_path);
+
+  base_filename = gtk_file_path_get_string (base_path);
   g_return_val_if_fail (base_filename != NULL, NULL);
+  g_return_val_if_fail (g_path_is_absolute (base_filename), NULL);
 
   filename = g_filename_from_utf8 (display_name, -1, NULL, NULL, &tmp_error);
   if (!filename)
@@ -351,19 +775,17 @@ gtk_file_system_unix_make_path (GtkFileSystem    *file_system,
                   GTK_FILE_SYSTEM_ERROR_BAD_FILENAME,
                   "%s",
                   tmp_error->message);
-      
+
       g_error_free (tmp_error);
-      g_free (base_filename);
 
-      return FALSE;
+      return NULL;
     }
-    
+
   full_filename = g_build_filename (base_filename, filename, NULL);
   result = filename_to_path (full_filename);
-  g_free (base_filename);
   g_free (filename);
   g_free (full_filename);
-  
+
   return result;
 }
 
@@ -398,7 +820,7 @@ canonicalize_filename (gchar *filename)
                {
                  if (*(p + 1) == '\0')
                    break;
-                 
+
                  p += 1;
                }
              else if (*(p + 1) == '.' &&
@@ -415,7 +837,7 @@ canonicalize_filename (gchar *filename)
 
                  if (*(p + 2) == '\0')
                    break;
-                 
+
                  p += 2;
                }
              else
@@ -448,13 +870,14 @@ gtk_file_system_unix_parse (GtkFileSystem     *file_system,
                            gchar            **file_part,
                            GError           **error)
 {
-  char *base_filename;
+  const char *base_filename;
   gchar *last_slash;
   gboolean result = FALSE;
 
-  base_filename = filename_from_path (base_path);
+  base_filename = gtk_file_path_get_string (base_path);
   g_return_val_if_fail (base_filename != NULL, FALSE);
-  
+  g_return_val_if_fail (g_path_is_absolute (base_filename), FALSE);
+
   last_slash = strrchr (str, G_DIR_SEPARATOR);
   if (!last_slash)
     {
@@ -494,7 +917,7 @@ gtk_file_system_unix_parse (GtkFileSystem     *file_system,
            }
 
          canonicalize_filename (folder_path);
-         
+
          *folder = filename_to_path (folder_path);
          *file_part = g_strdup (last_slash + 1);
 
@@ -504,8 +927,6 @@ gtk_file_system_unix_parse (GtkFileSystem     *file_system,
        }
     }
 
-  g_free (base_filename);
-  
   return result;
 }
 
@@ -541,27 +962,450 @@ gtk_file_system_unix_filename_to_path (GtkFileSystem *file_system,
   return gtk_file_path_new_dup (filename);
 }
 
-static gboolean
-gtk_file_system_unix_get_supports_bookmarks (GtkFileSystem *file_system)
+static const char *
+get_icon_for_directory (const char *path)
 {
-  return FALSE;
+  static char *desktop_path = NULL;
+
+  if (!g_get_home_dir ())
+    return "gnome-fs-directory";
+
+  if (!desktop_path)
+      desktop_path = g_build_filename (g_get_home_dir (), "Desktop", NULL);
+
+  if (strcmp (g_get_home_dir (), path) == 0)
+    return "gnome-fs-home";
+  else if (strcmp (desktop_path, path) == 0)
+    return "gnome-fs-desktop";
+  else
+    return "gnome-fs-directory";
+}
+
+static GdkPixbuf *
+gtk_file_system_unix_render_icon (GtkFileSystem     *file_system,
+                                 const GtkFilePath *path,
+                                 GtkWidget         *widget,
+                                 gint               pixel_size,
+                                 GError           **error)
+{
+  const char *filename;
+  IconType icon_type;
+  const char *mime_type = NULL;
+  char *dirname;
+  GtkFileSystemUnix *system_unix;
+  GtkFileFolderUnix *folder_unix;
+
+  system_unix = GTK_FILE_SYSTEM_UNIX (file_system);
+  filename = gtk_file_path_get_string (path);
+  dirname = g_path_get_dirname (filename);
+  folder_unix = g_hash_table_lookup (system_unix->folder_hash, dirname);
+  g_free (dirname);
+
+  if (folder_unix)
+    {
+      char *basename;
+      struct stat_info_entry *entry;
+
+      if (!fill_in_stats (folder_unix, error))
+       return NULL;
+
+      basename = g_path_get_basename (filename);
+      entry = g_hash_table_lookup (folder_unix->stat_info, basename);
+      g_free (basename);
+      if (entry)
+       {
+         if (entry->icon_type == ICON_UNDECIDED)
+           entry->icon_type = get_icon_type_from_stat (&entry->statbuf);
+         icon_type = entry->icon_type;
+         if (icon_type == ICON_REGULAR)
+           {
+             (void)fill_in_mime_type (folder_unix, NULL);
+             mime_type = entry->mime_type;
+           }
+       }
+      else
+       icon_type = ICON_NONE;
+    }
+  else
+    {
+#if 0
+      g_print ("No folder open for %s\n", filename);
+#endif
+
+      icon_type = get_icon_type (filename, error);
+      if (icon_type == ICON_REGULAR)
+       mime_type = xdg_mime_get_mime_type_for_file (filename);
+    }
+
+
+  /* FIXME: this function should not return NULL without setting the GError; we
+   * should perhaps provide a "never fails" generic stock icon for when all else
+   * fails.
+   */
+
+  if (icon_type == ICON_NONE)
+    return NULL;
+
+  if (icon_type != ICON_REGULAR)
+    {
+      const char *name;
+
+      switch (icon_type)
+       {
+       case ICON_BLOCK_DEVICE:
+          name = "gnome-fs-blockdev";
+         break;
+       case ICON_BROKEN_SYMBOLIC_LINK:
+         name = "gnome-fs-symlink";
+         break;
+       case ICON_CHARACTER_DEVICE:
+         name = "gnome-fs-chardev";
+         break;
+       case ICON_DIRECTORY:
+         name = get_icon_for_directory (filename);
+         break;
+       case ICON_EXECUTABLE:
+         name ="gnome-fs-executable";
+         break;
+       case ICON_FIFO:
+         name = "gnome-fs-fifo";
+         break;
+       case ICON_SOCKET:
+         name = "gnome-fs-socket";
+         break;
+       default:
+         g_assert_not_reached ();
+         return NULL;
+       }
+
+      return get_cached_icon (widget, name, pixel_size);
+    }
+
+  if (mime_type)
+    {
+      const char *separator;
+      GString *icon_name;
+      GdkPixbuf *pixbuf;
+
+      separator = strchr (mime_type, '/');
+      if (!separator)
+       return NULL;
+
+      icon_name = g_string_new ("gnome-mime-");
+      g_string_append_len (icon_name, mime_type, separator - mime_type);
+      g_string_append_c (icon_name, '-');
+      g_string_append (icon_name, separator + 1);
+      pixbuf = get_cached_icon (widget, icon_name->str, pixel_size);
+      g_string_free (icon_name, TRUE);
+      if (pixbuf)
+       return pixbuf;
+
+      icon_name = g_string_new ("gnome-mime-");
+      g_string_append_len (icon_name, mime_type, separator - mime_type);
+      pixbuf = get_cached_icon (widget, icon_name->str, pixel_size);
+      g_string_free (icon_name, TRUE);
+      if (pixbuf)
+       return pixbuf;
+    }
+
+  return get_cached_icon (widget, "gnome-fs-regular", pixel_size);
 }
 
 static void
-gtk_file_system_unix_set_bookmarks (GtkFileSystem *file_system,
-                                   GSList        *bookmarks,
-                                   GError       **error)
+bookmark_list_free (GSList *list)
+{
+  GSList *l;
+
+  for (l = list; l; l = l->next)
+    g_free (l->data);
+
+  g_slist_free (list);
+}
+
+/* Returns whether a URI is a local file:// */
+static gboolean
+is_local_uri (const char *uri)
+{
+  char *filename;
+  char *hostname;
+  gboolean result;
+
+  /* This is rather crude, but hey */
+  filename = g_filename_from_uri (uri, &hostname, NULL);
+
+  result = (filename && !hostname);
+
+  g_free (filename);
+  g_free (hostname);
+
+  return result;
+}
+
+static char *
+bookmark_get_filename (gboolean tmp_file)
+{
+  char *filename;
+
+  filename = g_build_filename (g_get_home_dir (),
+                              tmp_file ? BOOKMARKS_TMP_FILENAME : BOOKMARKS_FILENAME,
+                              NULL);
+  g_assert (filename != NULL);
+  return filename;
+}
+
+static gboolean
+bookmark_list_read (GSList **bookmarks, GError **error)
+{
+  gchar *filename;
+  gchar *contents;
+  gboolean result = FALSE;
+
+  filename = bookmark_get_filename (FALSE);
+  *bookmarks = NULL;
+
+  if (g_file_get_contents (filename, &contents, NULL, error))
+    {
+      gchar **lines = g_strsplit (contents, "\n", -1);
+      int i;
+      GHashTable *table;
+
+      table = g_hash_table_new (g_str_hash, g_str_equal);
+
+      for (i = 0; lines[i]; i++)
+       {
+         if (lines[i][0] && !g_hash_table_lookup (table, lines[i]))
+           {
+             *bookmarks = g_slist_prepend (*bookmarks, g_strdup (lines[i]));
+             g_hash_table_insert (table, lines[i], lines[i]);
+           }
+       }
+
+      g_free (contents);
+      g_hash_table_destroy (table);
+      g_strfreev (lines);
+
+      *bookmarks = g_slist_reverse (*bookmarks);
+      result = TRUE;
+    }
+
+  g_free (filename);
+
+  return result;
+}
+
+static gboolean
+bookmark_list_write (GSList *bookmarks, GError **error)
 {
+  char *tmp_filename;
+  char *filename;
+  gboolean result = TRUE;
+  FILE *file;
+  int fd;
+  int saved_errno;
+
+  /* First, write a temporary file */
+
+  tmp_filename = bookmark_get_filename (TRUE);
+  filename = bookmark_get_filename (FALSE);
+
+  fd = g_mkstemp (tmp_filename);
+  if (fd == -1)
+    {
+      saved_errno = errno;
+      goto io_error;
+    }
+
+  if ((file = fdopen (fd, "w")) != NULL)
+    {
+      GSList *l;
+
+      for (l = bookmarks; l; l = l->next)
+       if (fputs (l->data, file) == EOF
+           || fputs ("\n", file) == EOF)
+         {
+           saved_errno = errno;
+           goto io_error;
+         }
+
+      if (fclose (file) == EOF)
+       {
+         saved_errno = errno;
+         goto io_error;
+       }
+
+      if (rename (tmp_filename, filename) == -1)
+       {
+         saved_errno = errno;
+         goto io_error;
+       }
+
+      result = TRUE;
+      goto out;
+    }
+  else
+    {
+      saved_errno = errno;
+
+      /* fdopen() failed, so we can't do much error checking here anyway */
+      close (fd);
+    }
+
+ io_error:
+
   g_set_error (error,
               GTK_FILE_SYSTEM_ERROR,
               GTK_FILE_SYSTEM_ERROR_FAILED,
-              "This file system does not support bookmarks"); 
+              _("Bookmark saving failed (%s)"),
+              g_strerror (saved_errno));
+  result = FALSE;
+
+  if (fd != -1)
+    unlink (tmp_filename); /* again, not much error checking we can do here */
+
+ out:
+
+  g_free (filename);
+  g_free (tmp_filename);
+
+  return result;
+}
+
+static gboolean
+gtk_file_system_unix_insert_bookmark (GtkFileSystem     *file_system,
+                                     const GtkFilePath *path,
+                                     gint               position,
+                                     GError           **error)
+{
+  GSList *bookmarks;
+  int num_bookmarks;
+  GSList *l;
+  char *uri;
+  gboolean result;
+  GError *err;
+
+  err = NULL;
+  if (!bookmark_list_read (&bookmarks, &err) && err->code != G_FILE_ERROR_NOENT)
+    {
+      g_propagate_error (error, err);
+      return FALSE;
+    }
+
+  num_bookmarks = g_slist_length (bookmarks);
+  g_return_val_if_fail (position >= -1 && position <= num_bookmarks, FALSE);
+
+  result = FALSE;
+
+  uri = gtk_file_system_unix_path_to_uri (file_system, path);
+
+  for (l = bookmarks; l; l = l->next)
+    {
+      const char *bookmark;
+
+      bookmark = l->data;
+      if (strcmp (bookmark, uri) == 0)
+       {
+         g_set_error (error,
+                      GTK_FILE_SYSTEM_ERROR,
+                      GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS,
+                      "%s already exists in the bookmarks list",
+                      uri);
+         goto out;
+       }
+    }
+
+  bookmarks = g_slist_insert (bookmarks, g_strdup (uri), position);
+  if (bookmark_list_write (bookmarks, error))
+    {
+      result = TRUE;
+      g_signal_emit_by_name (file_system, "bookmarks-changed", 0);
+    }
+
+ out:
+
+  g_free (uri);
+  bookmark_list_free (bookmarks);
+
+  return result;
+}
+
+static gboolean
+gtk_file_system_unix_remove_bookmark (GtkFileSystem     *file_system,
+                                     const GtkFilePath *path,
+                                     GError           **error)
+{
+  GSList *bookmarks;
+  char *uri;
+  GSList *l;
+  gboolean result;
+
+  if (!bookmark_list_read (&bookmarks, error))
+    return FALSE;
+
+  result = FALSE;
+
+  uri = gtk_file_system_path_to_uri (file_system, path);
+
+  for (l = bookmarks; l; l = l->next)
+    {
+      const char *bookmark;
+
+      bookmark = l->data;
+      if (strcmp (bookmark, uri) == 0)
+       {
+         g_free (l->data);
+         bookmarks = g_slist_remove_link (bookmarks, l);
+         g_slist_free_1 (l);
+
+         if (bookmark_list_write (bookmarks, error))
+           {
+             result = TRUE;
+             g_signal_emit_by_name (file_system, "bookmarks-changed", 0);
+           }
+
+         goto out;
+       }
+    }
+
+  g_set_error (error,
+              GTK_FILE_SYSTEM_ERROR,
+              GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
+              "%s does not exist in the bookmarks list",
+              uri);
+
+ out:
+
+  g_free (uri);
+  bookmark_list_free (bookmarks);
+
+  return result;
 }
 
 static GSList *
 gtk_file_system_unix_list_bookmarks (GtkFileSystem *file_system)
 {
-  return NULL;
+  GSList *bookmarks;
+  GSList *result;
+  GSList *l;
+
+  if (!bookmark_list_read (&bookmarks, NULL))
+    return NULL;
+
+  result = NULL;
+
+  for (l = bookmarks; l; l = l->next)
+    {
+      const char *name;
+
+      name = l->data;
+
+      if (is_local_uri (name))
+       result = g_slist_prepend (result, gtk_file_system_unix_uri_to_path (file_system, name));
+    }
+
+  bookmark_list_free (bookmarks);
+
+  result = g_slist_reverse (result);
+  return result;
 }
 
 /*
@@ -586,7 +1430,7 @@ gtk_file_folder_unix_get_type (void)
        0,              /* n_preallocs */
        (GInstanceInitFunc) gtk_file_folder_unix_init,
       };
-      
+
       static const GInterfaceInfo file_folder_info =
       {
        (GInterfaceInitFunc) gtk_file_folder_unix_iface_init, /* interface_init */
@@ -632,193 +1476,281 @@ gtk_file_folder_unix_finalize (GObject *object)
 {
   GtkFileFolderUnix *folder_unix = GTK_FILE_FOLDER_UNIX (object);
 
+  g_hash_table_remove (folder_unix->system_unix->folder_hash, folder_unix->filename);
+
+  if (folder_unix->stat_info)
+    {
+#if 0
+      g_print ("Releasing information for directory %s\n", folder_unix->filename);
+#endif
+      g_hash_table_destroy (folder_unix->stat_info);
+    }
+
   g_free (folder_unix->filename);
-  
+
   folder_parent_class->finalize (object);
 }
 
 static GtkFileInfo *
-gtk_file_folder_unix_get_info (GtkFileFolder  *folder,
-                              const GtkFilePath    *path,
-                              GError        **error)
+gtk_file_folder_unix_get_info (GtkFileFolder      *folder,
+                              const GtkFilePath  *path,
+                              GError            **error)
 {
   GtkFileFolderUnix *folder_unix = GTK_FILE_FOLDER_UNIX (folder);
   GtkFileInfo *info;
-  gchar *dirname;
-  gchar *filename;
-  
-  filename = filename_from_path (path);
+  gchar *dirname, *basename;
+  const char *filename;
+  struct stat_info_entry *entry;
+  gboolean file_must_exist;
+  GtkFileInfoType types;
+
+  if (!path)
+    {
+      struct stat buf;
+
+      g_return_val_if_fail (filename_is_root (folder_unix->filename), NULL);
+
+      if (stat (folder_unix->filename, &buf) != 0)
+       return NULL;
+
+      info = gtk_file_info_new ();
+      gtk_file_info_set_display_name (info, "/");
+      gtk_file_info_set_is_folder (info, TRUE);
+      gtk_file_info_set_is_hidden (info, FALSE);
+      gtk_file_info_set_mime_type (info, "x-directory/normal");
+      gtk_file_info_set_modification_time (info, buf.st_mtime);
+      gtk_file_info_set_size (info, buf.st_size);
+
+      return info;
+    }
+
+  filename = gtk_file_path_get_string (path);
   g_return_val_if_fail (filename != NULL, NULL);
+  g_return_val_if_fail (g_path_is_absolute (filename), NULL);
 
-  dirname = g_path_get_dirname (filename);
+  dirname = get_parent_dir (filename);
   g_return_val_if_fail (strcmp (dirname, folder_unix->filename) == 0, NULL);
   g_free (dirname);
 
-  info = filename_get_info (filename, folder_unix->types, error);
+  basename = g_path_get_basename (filename);
+  types = folder_unix->types;
+  file_must_exist = (types & ~GTK_FILE_INFO_DISPLAY_NAME) != 0;
+  entry = file_must_exist
+    ? g_hash_table_lookup (folder_unix->stat_info, basename)
+    : NULL;
+  /* basename freed later.  */
 
-  g_free (filename);
+  if (!file_must_exist || entry)
+    {
+      info = gtk_file_info_new ();
+    }
+  else
+    {
+      gchar *filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
+      g_set_error (error,
+                  GTK_FILE_SYSTEM_ERROR,
+                  GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
+                  _("error getting information for '%s'"),
+                  filename_utf8 ? filename_utf8 : "???");
+      g_free (filename_utf8);
+      info = NULL;
+      types = 0;
+    }
+
+  if (types & GTK_FILE_INFO_DISPLAY_NAME)
+    {
+      gchar *display_name = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
+      if (!display_name)
+       display_name = g_strescape (basename, NULL);
+
+      gtk_file_info_set_display_name (info, display_name);
+
+      g_free (display_name);
+    }
+
+  if (types & GTK_FILE_INFO_IS_HIDDEN)
+    gtk_file_info_set_is_hidden (info, basename[0] == '.');
+
+  if (types & GTK_FILE_INFO_IS_FOLDER)
+    gtk_file_info_set_is_folder (info, S_ISDIR (entry->statbuf.st_mode));
+
+  if (types & GTK_FILE_INFO_MIME_TYPE)
+    gtk_file_info_set_mime_type (info, entry->mime_type);
+
+  if (types & GTK_FILE_INFO_MODIFICATION_TIME)
+    gtk_file_info_set_modification_time (info, entry->statbuf.st_mtime);
+
+  if (types & GTK_FILE_INFO_SIZE)
+    gtk_file_info_set_size (info, (gint64)entry->statbuf.st_size);
+
+  g_free (basename);
 
   return info;
 }
 
+
+static void
+cb_list_children (gpointer key, gpointer value, gpointer user_data)
+{
+  GSList **children = user_data;
+  *children = g_slist_prepend (*children, key);
+}
+
 static gboolean
 gtk_file_folder_unix_list_children (GtkFileFolder  *folder,
                                    GSList        **children,
                                    GError        **error)
 {
   GtkFileFolderUnix *folder_unix = GTK_FILE_FOLDER_UNIX (folder);
-  GError *tmp_error = NULL;
-  GDir *dir;
+  GSList *l;
+
+  if (!fill_in_names (folder_unix, error))
+    return FALSE;
 
   *children = NULL;
 
-  dir = g_dir_open (folder_unix->filename, 0, &tmp_error);
+  /* Get the list of basenames.  */
+  g_hash_table_foreach (folder_unix->stat_info, cb_list_children, children);
+
+  /* Turn basenames into GFilePaths.  */
+  for (l = *children; l; l = l->next)
+    {
+      const char *basename = l->data;
+      char *fullname = g_build_filename (folder_unix->filename, basename, NULL);
+      l->data = filename_to_path (fullname);
+      g_free (fullname);
+    }
+  return TRUE;
+}
+
+
+static void
+free_stat_info_entry (struct stat_info_entry *entry)
+{
+  g_free (entry->mime_type);
+  g_free (entry);
+}
+
+static gboolean
+fill_in_names (GtkFileFolderUnix *folder_unix, GError **error)
+{
+  GDir *dir;
+
+  if (folder_unix->stat_info)
+    return TRUE;
+
+#if 0
+  g_print ("Reading directory %s\n", folder_unix->filename);
+#endif
+
+  folder_unix->stat_info = g_hash_table_new_full (g_str_hash, g_str_equal,
+                                                 (GDestroyNotify)g_free,
+                                                 (GDestroyNotify)free_stat_info_entry);
+  dir = g_dir_open (folder_unix->filename, 0, error);
   if (!dir)
     {
+      int save_errno = errno;
+      gchar *filename_utf8 = g_filename_to_utf8 (folder_unix->filename, -1, NULL, NULL, NULL);
       g_set_error (error,
                   GTK_FILE_SYSTEM_ERROR,
                   GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
-                  "%s",
-                  tmp_error->message);
-      
-      g_error_free (tmp_error);
-
+                  _("error getting information for '%s': %s"),
+                  filename_utf8 ? filename_utf8 : "???",
+                  g_strerror (save_errno));
+      g_free (filename_utf8);
       return FALSE;
     }
 
   while (TRUE)
     {
-      const gchar *filename = g_dir_read_name (dir);
-      gchar *fullname;
-
-      if (!filename)
+      const gchar *basename = g_dir_read_name (dir);
+      if (!basename)
        break;
 
-      fullname = g_build_filename (folder_unix->filename, filename, NULL);
-      *children = g_slist_prepend (*children, filename_to_path (fullname));
-      g_free (fullname);
+      g_hash_table_insert (folder_unix->stat_info,
+                          g_strdup (basename),
+                          g_new0 (struct stat_info_entry, 1));
     }
 
   g_dir_close (dir);
 
-  *children = g_slist_reverse (*children);
-  
+  folder_unix->asof = time (NULL);
   return TRUE;
 }
 
-static GtkFileInfo *
-filename_get_info (const gchar     *filename,
-                  GtkFileInfoType  types,
-                  GError         **error)
+static gboolean
+cb_fill_in_stats (gpointer key, gpointer value, gpointer user_data)
 {
-  GtkFileInfo *info;
-  GtkFileIconType icon_type = GTK_FILE_ICON_REGULAR;
-  struct stat statbuf;
-  
-  /* If stat fails, try to fall back to lstat to catch broken links
-   */
-  if (stat (filename, &statbuf) != 0 &&
-      lstat (filename, &statbuf) != 0)
-    {
-      gchar *filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
-      g_set_error (error,
-                  GTK_FILE_SYSTEM_ERROR,
-                  GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
-                  "error getting information for '%s': %s",
-                  filename_utf8 ? filename_utf8 : "???",
-                  g_strerror (errno));
-      g_free (filename_utf8);
-      
-      return NULL;
-    }
-
-  info = gtk_file_info_new ();
+  const char *basename = key;
+  struct stat_info_entry *entry = value;
+  GtkFileFolderUnix *folder_unix = user_data;
+  char *fullname = g_build_filename (folder_unix->filename, basename, NULL);
+  gboolean result;
 
-  if (filename_is_root (filename))
-    {
-      if (types & GTK_FILE_INFO_DISPLAY_NAME)
-       gtk_file_info_set_display_name (info, "/");
-      
-      if (types & GTK_FILE_INFO_IS_HIDDEN)
-       gtk_file_info_set_is_hidden (info, FALSE);
-    }
+  if (stat (fullname, &entry->statbuf) == -1 &&
+      (errno != ENOENT || lstat (fullname, &entry->statbuf) == -1))
+    result = TRUE;  /* Couldn't stat -- remove from hash.  */
   else
-    {
-      gchar *basename = g_path_get_basename (filename);
-  
-      if (types & GTK_FILE_INFO_DISPLAY_NAME)
-       {
-         gchar *display_name = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
-         if (!display_name)
-           display_name = g_strescape (basename, NULL);
-         
-         gtk_file_info_set_display_name (info, display_name);
-         
-         g_free (display_name);
-       }
-      
-      if (types & GTK_FILE_INFO_IS_HIDDEN)
-       {
-         gtk_file_info_set_is_hidden (info, basename[0] == '.');
-       }
+    result = FALSE;
 
-      g_free (basename);
-    }
+  g_free (fullname);
+  return result;
+}
 
-  if (types & GTK_FILE_INFO_IS_FOLDER)
-    {
-      gtk_file_info_set_is_folder (info, S_ISDIR (statbuf.st_mode));
-   }
 
-  if (types & GTK_FILE_INFO_ICON)
-    {
-      if (S_ISBLK (statbuf.st_mode))
-       icon_type = GTK_FILE_ICON_BLOCK_DEVICE;
-      else if (S_ISLNK (statbuf.st_mode))
-       icon_type = GTK_FILE_ICON_BROKEN_SYMBOLIC_LINK;
-      else if (S_ISCHR (statbuf.st_mode))
-       icon_type = GTK_FILE_ICON_CHARACTER_DEVICE;
-      else if (S_ISDIR (statbuf.st_mode))
-       icon_type = GTK_FILE_ICON_DIRECTORY;
-      else if (S_ISFIFO (statbuf.st_mode))
-       icon_type =  GTK_FILE_ICON_FIFO;
-      else if (S_ISSOCK (statbuf.st_mode))
-       icon_type = GTK_FILE_ICON_SOCKET;
+static gboolean
+fill_in_stats (GtkFileFolderUnix *folder_unix, GError **error)
+{
+  if (folder_unix->have_stat)
+    return TRUE;
 
-      gtk_file_info_set_icon_type (info, icon_type);
-    }
+  if (!fill_in_names (folder_unix, error))
+    return FALSE;
 
-  if ((types & GTK_FILE_INFO_MIME_TYPE) ||
-      ((types & GTK_FILE_INFO_ICON) && icon_type == GTK_FILE_ICON_REGULAR))
-    {
-      const char *mime_type = xdg_mime_get_mime_type_for_file (filename);
-      gtk_file_info_set_mime_type (info, mime_type);
+#if 0
+  g_print ("Stating directory %s\n", folder_unix->filename);
+#endif
+  g_hash_table_foreach_remove (folder_unix->stat_info,
+                              cb_fill_in_stats,
+                              folder_unix);
 
-      if ((types & GTK_FILE_INFO_ICON) && icon_type == GTK_FILE_ICON_REGULAR &&
-         (statbuf.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) &&
-         (strcmp (mime_type, XDG_MIME_TYPE_UNKNOWN) == 0 ||
-          strcmp (mime_type, "application/x-executable") == 0 ||
-          strcmp (mime_type, "application/x-shellscript") == 0))
-       gtk_file_info_set_icon_type (info, GTK_FILE_ICON_EXECUTABLE);
-    }
+  folder_unix->have_stat = TRUE;
+  return TRUE;
+}
 
-  if (types & GTK_FILE_INFO_MODIFICATION_TIME)
-    {
-      gtk_file_info_set_modification_time (info, statbuf.st_mtime);
-    }
 
-  if (types & GTK_FILE_INFO_SIZE)
-    {
-      gtk_file_info_set_size (info, (gint64)statbuf.st_size);
-    }
-  
-  return info;
+static gboolean
+cb_fill_in_mime_type (gpointer key, gpointer value, gpointer user_data)
+{
+  const char *basename = key;
+  struct stat_info_entry *entry = value;
+  GtkFileFolderUnix *folder_unix = user_data;
+  char *fullname = g_build_filename (folder_unix->filename, basename, NULL);
+
+  /* FIXME: Should not need to re-stat.  */
+  const char *mime_type = xdg_mime_get_mime_type_for_file (fullname);
+  entry->mime_type = g_strdup (mime_type);
+
+  g_free (fullname);
+  /* FIXME: free on NULL?  */
+  return FALSE;
 }
 
-static gchar *
-filename_from_path (const GtkFilePath *path)
+static gboolean
+fill_in_mime_type (GtkFileFolderUnix *folder_unix, GError **error)
 {
-  return g_strdup (gtk_file_path_get_string (path));
+  if (folder_unix->have_mime_type)
+    return TRUE;
+
+#if 0
+  g_print ("Getting mime types for directory %s\n", folder_unix->filename);
+#endif
+  g_hash_table_foreach_remove (folder_unix->stat_info,
+                              cb_fill_in_mime_type,
+                              folder_unix);
+
+  folder_unix->have_mime_type = TRUE;
+  return TRUE;
 }
 
 static GtkFilePath *
@@ -831,8 +1763,8 @@ static gboolean
 filename_is_root (const char *filename)
 {
   const gchar *after_root;
-  
+
   after_root = g_path_skip_root (filename);
-  
-  return (*after_root == '\0');
+
+  return (after_root != NULL && *after_root == '\0');
 }