[gnome-commander] Check dirs if they are up-to-date before reusing them
- From: Piotr Eljasiak <epiotr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Check dirs if they are up-to-date before reusing them
- Date: Tue, 10 Aug 2010 20:39:00 +0000 (UTC)
commit 064e5b1e4918b2a78c4f9d439c64f14cddbe6b59
Author: phan <phanyx o2 pl>
Date: Tue Aug 10 22:38:23 2010 +0200
Check dirs if they are up-to-date before reusing them
When a visited, but not being displayed directory is
modified outside the gcmd (e.g. new files are created),
this directory remains unrefreshed, since it has vfs
monitor's callbacks cut off. So there's a need for checking
if it is up-to-date, before reusing it.
src/gnome-cmd-dir.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++
src/gnome-cmd-dir.h | 3 ++
src/gnome-cmd-file-list.cc | 11 ++++++++-
3 files changed, 60 insertions(+), 2 deletions(-)
---
diff --git a/src/gnome-cmd-dir.cc b/src/gnome-cmd-dir.cc
index ce190c7..8d20042 100644
--- a/src/gnome-cmd-dir.cc
+++ b/src/gnome-cmd-dir.cc
@@ -64,6 +64,7 @@ struct GnomeCmdDirPrivate
GnomeCmdPath *path;
gboolean lock;
+ gboolean needs_mtime_update;
Handle *handle;
GnomeVFSMonitorHandle *monitor_handle;
@@ -284,6 +285,7 @@ GnomeCmdDir *gnome_cmd_dir_new_from_info (GnomeVFSFileInfo *info, GnomeCmdDir *p
dir->priv->con = con;
gnome_cmd_dir_set_path (dir, path);
gtk_object_ref (GTK_OBJECT (path));
+ dir->priv->needs_mtime_update = FALSE;
gnome_cmd_con_add_to_cache (gnome_cmd_dir_get_connection (parent), dir);
@@ -314,6 +316,7 @@ GnomeCmdDir *gnome_cmd_dir_new_with_con (GnomeVFSFileInfo *info, GnomeCmdPath *p
dir->priv->con = con;
gnome_cmd_dir_set_path (dir, path);
gtk_object_ref (GTK_OBJECT (path));
+ dir->priv->needs_mtime_update = FALSE;
gnome_cmd_con_add_to_cache (con, dir);
@@ -354,6 +357,7 @@ GnomeCmdDir *gnome_cmd_dir_new (GnomeCmdCon *con, GnomeCmdPath *path)
dir->priv->con = con;
gnome_cmd_dir_set_path (dir, path);
gtk_object_ref (GTK_OBJECT (path));
+ dir->priv->needs_mtime_update = FALSE;
gnome_cmd_con_add_to_cache (con, dir);
}
@@ -742,6 +746,8 @@ void gnome_cmd_dir_file_created (GnomeCmdDir *dir, const gchar *uri_str)
dir->priv->file_collection->add(f);
dir->priv->files = dir->priv->file_collection->get_list();
+ dir->priv->needs_mtime_update = TRUE;
+
gtk_signal_emit (GTK_OBJECT (dir), dir_signals[FILE_CREATED], f);
}
@@ -757,6 +763,8 @@ void gnome_cmd_dir_file_deleted (GnomeCmdDir *dir, const gchar *uri_str)
if (!GNOME_CMD_IS_FILE (f))
return;
+ dir->priv->needs_mtime_update = TRUE;
+
gtk_signal_emit (GTK_OBJECT (dir), dir_signals[FILE_DELETED], f);
dir->priv->file_collection->remove(uri_str);
@@ -779,6 +787,8 @@ void gnome_cmd_dir_file_changed (GnomeCmdDir *dir, const gchar *uri_str)
GnomeVFSResult res = gnome_vfs_get_file_info_uri (uri, info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE);
gnome_vfs_uri_unref (uri);
+ dir->priv->needs_mtime_update = TRUE;
+
gnome_cmd_file_update_info (f, info);
gnome_cmd_file_invalidate_metadata (f);
gtk_signal_emit (GTK_OBJECT (dir), dir_signals[FILE_CHANGED], f);
@@ -794,6 +804,8 @@ void gnome_cmd_dir_file_renamed (GnomeCmdDir *dir, GnomeCmdFile *f, const gchar
if (GNOME_CMD_IS_DIR (f))
gnome_cmd_con_remove_from_cache (dir->priv->con, old_uri_str);
+ dir->priv->needs_mtime_update = TRUE;
+
dir->priv->file_collection->remove(old_uri_str);
dir->priv->file_collection->add(f);
gtk_signal_emit (GTK_OBJECT (dir), dir_signals[FILE_RENAMED], f);
@@ -878,3 +890,39 @@ gboolean gnome_cmd_dir_is_local (GnomeCmdDir *dir)
return gnome_cmd_con_is_local (dir->priv->con);
}
+
+
+gboolean gnome_cmd_dir_update_mtime (GnomeCmdDir *dir)
+{
+ // this function also determines if cached dir is up-to-date (FALSE=yes)
+ g_return_val_if_fail (GNOME_CMD_IS_DIR (dir), FALSE);
+
+ // assume cache is updated
+ gboolean returnValue = FALSE;
+ GnomeVFSURI *uri = gnome_cmd_dir_get_uri (dir);
+ GnomeVFSFileInfo *info = gnome_vfs_file_info_new ();
+ GnomeVFSResult res = gnome_vfs_get_file_info_uri (uri, info, (GnomeVFSFileInfoOptions)
+ (GNOME_VFS_FILE_INFO_FOLLOW_LINKS | GNOME_VFS_FILE_INFO_NAME_ONLY));
+ if (res != GNOME_VFS_OK || GNOME_CMD_FILE(dir)->info->mtime != info->mtime)
+ {
+ // cache is not up-to-date
+ GNOME_CMD_FILE (dir)->info->mtime = info->mtime;
+ returnValue = TRUE;
+ }
+
+ gnome_vfs_file_info_unref (info);
+ gnome_vfs_uri_unref (uri);
+
+ // after this function we are sure dir's mtime is up-to-date
+ dir->priv->needs_mtime_update = FALSE;
+
+ return returnValue;
+}
+
+
+gboolean gnome_cmd_dir_needs_mtime_update (GnomeCmdDir *dir)
+{
+ g_return_val_if_fail (GNOME_CMD_IS_DIR (dir), FALSE);
+
+ return dir->priv->needs_mtime_update;
+}
diff --git a/src/gnome-cmd-dir.h b/src/gnome-cmd-dir.h
index d37e2e4..1ec4f63 100644
--- a/src/gnome-cmd-dir.h
+++ b/src/gnome-cmd-dir.h
@@ -150,6 +150,9 @@ gboolean gnome_cmd_dir_is_monitored (GnomeCmdDir *dir);
gboolean gnome_cmd_dir_is_local (GnomeCmdDir *dir);
void gnome_cmd_dir_set_content_changed (GnomeCmdDir *dir);
+gboolean gnome_cmd_dir_update_mtime (GnomeCmdDir *dir);
+gboolean gnome_cmd_dir_needs_mtime_update (GnomeCmdDir *dir);
+
inline gchar *gnome_cmd_dir_get_free_space (GnomeCmdDir *dir)
{
g_return_val_if_fail (GNOME_CMD_IS_DIR (dir), NULL);
diff --git a/src/gnome-cmd-file-list.cc b/src/gnome-cmd-file-list.cc
index f68b8e5..afb71c7 100644
--- a/src/gnome-cmd-file-list.cc
+++ b/src/gnome-cmd-file-list.cc
@@ -2552,9 +2552,11 @@ void GnomeCmdFileList::set_directory(GnomeCmdDir *dir)
if (cwd)
{
- gnome_cmd_dir_cancel_monitoring (cwd);
lwd = cwd;
+ gnome_cmd_dir_cancel_monitoring (lwd);
g_signal_handlers_disconnect_matched (lwd, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, this);
+ if (gnome_cmd_dir_is_local (lwd) && !gnome_cmd_dir_is_monitored (lwd) && gnome_cmd_dir_needs_mtime_update (lwd))
+ gnome_cmd_dir_update_mtime (lwd);
cwd->voffset = gnome_cmd_clist_get_voffset (*this);
}
@@ -2577,7 +2579,12 @@ void GnomeCmdFileList::set_directory(GnomeCmdDir *dir)
case DIR_STATE_LISTED:
g_signal_connect (dir, "list-ok", G_CALLBACK (on_dir_list_ok), this);
g_signal_connect (dir, "list-failed", G_CALLBACK (on_dir_list_failed), this);
- on_dir_list_ok (dir, NULL, this);
+
+ // check if the dir has up-to-date file list; if not and it's a local dir - relist it
+ if (gnome_cmd_dir_is_local (dir) && !gnome_cmd_dir_is_monitored (dir) && gnome_cmd_dir_update_mtime (dir))
+ gnome_cmd_dir_relist_files (dir, gnome_cmd_con_needs_list_visprog (con));
+ else
+ on_dir_list_ok (dir, NULL, this);
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]