[gedit] Rework externally modified / deleted check
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Rework externally modified / deleted check
- Date: Sat, 22 Dec 2012 20:55:38 +0000 (UTC)
commit 7c5e872ad6556c14714ffd87f8e9c235d71a9d9c
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Dec 22 21:46:53 2012 +0100
Rework externally modified / deleted check
If we already know a doc was externally modified or deleted do not stat
again
gedit/gedit-document.c | 132 +++++++++++++++++++++++++++++-------------------
1 files changed, 80 insertions(+), 52 deletions(-)
---
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index 8c56665..04f4bf8 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -144,6 +144,8 @@ struct _GeditDocumentPrivate
gpointer mount_operation_userdata;
guint readonly : 1;
+ guint externally_modified : 1;
+ guint deleted : 1;
guint last_save_was_manually : 1;
guint language_set_by_user : 1;
guint stop_cursor_moved_emission : 1;
@@ -1346,56 +1348,6 @@ gedit_document_get_readonly (GeditDocument *doc)
return doc->priv->readonly;
}
-gboolean
-_gedit_document_check_externally_modified (GeditDocument *doc)
-{
- GFileInfo *info;
-
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
-
- if (doc->priv->location == NULL)
- {
- return FALSE;
- }
-
- info = g_file_query_info (doc->priv->location,
- G_FILE_ATTRIBUTE_TIME_MODIFIED "," \
- G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
- G_FILE_QUERY_INFO_NONE,
- NULL, NULL);
-
- if (info != NULL)
- {
- /* While at it also check if permissions changed */
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
- {
- gboolean read_only;
-
- read_only = !g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
-
- _gedit_document_set_readonly (doc, read_only);
- }
-
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
- {
- GTimeVal timeval;
-
- g_file_info_get_modification_time (info, &timeval);
-
- g_object_unref (info);
-
- return (timeval.tv_sec > doc->priv->mtime.tv_sec) ||
- (timeval.tv_sec == doc->priv->mtime.tv_sec &&
- timeval.tv_usec > doc->priv->mtime.tv_usec);
- }
-
- g_object_unref (info);
- }
-
- return FALSE;
-}
-
static void
reset_temp_loading_data (GeditDocument *doc)
{
@@ -1450,6 +1402,9 @@ document_loader_loaded (GeditDocumentLoader *loader,
g_get_current_time (&doc->priv->time_of_last_save_or_load);
+ doc->priv->externally_modified = FALSE;
+ doc->priv->deleted = FALSE;
+
set_encoding (doc,
gedit_document_loader_get_encoding (loader),
(doc->priv->requested_encoding != NULL));
@@ -1749,6 +1704,9 @@ document_saver_saving (GeditDocumentSaver *saver,
g_get_current_time (&doc->priv->time_of_last_save_or_load);
+ doc->priv->externally_modified = FALSE;
+ doc->priv->deleted = FALSE;
+
_gedit_document_set_readonly (doc, FALSE);
gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc),
@@ -1942,13 +1900,83 @@ gedit_document_is_local (GeditDocument *doc)
return gedit_utils_location_has_file_scheme (doc->priv->location);
}
+static void
+check_file_on_disk (GeditDocument *doc)
+{
+ GFileInfo *info;
+
+ if (doc->priv->location == NULL)
+ {
+ return;
+ }
+
+ info = g_file_query_info (doc->priv->location,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED "," \
+ G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
+ G_FILE_QUERY_INFO_NONE,
+ NULL, NULL);
+
+ if (info != NULL)
+ {
+ /* While at it also check if permissions changed */
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
+ {
+ gboolean read_only;
+
+ read_only = !g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+
+ _gedit_document_set_readonly (doc, read_only);
+ }
+
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
+ {
+ GTimeVal timeval;
+
+ g_file_info_get_modification_time (info, &timeval);
+
+ g_object_unref (info);
+
+ if (timeval.tv_sec > doc->priv->mtime.tv_sec ||
+ (timeval.tv_sec == doc->priv->mtime.tv_sec &&
+ timeval.tv_usec > doc->priv->mtime.tv_usec))
+ {
+ doc->priv->externally_modified = TRUE;
+ }
+ }
+
+ g_object_unref (info);
+ }
+ else
+ {
+ doc->priv->deleted = TRUE;
+ }
+}
+
+gboolean
+_gedit_document_check_externally_modified (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+
+ if (!doc->priv->externally_modified)
+ {
+ check_file_on_disk (doc);
+ }
+
+ return doc->priv->externally_modified;
+}
+
gboolean
gedit_document_get_deleted (GeditDocument *doc)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
- /* This is done sync, maybe we should do it async? */
- return doc->priv->location && !g_file_query_exists (doc->priv->location, NULL);
+ if (!doc->priv->deleted)
+ {
+ check_file_on_disk (doc);
+ }
+
+ return doc->priv->deleted;
}
/*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]