Hi.
I don't know whether it was this change which caused this, but after I
updated recently to r5395 and turned on the #define in document.c which
controls using GIO file monitor, each time I save a document (I only
use local filesystems) I get a dialog telling me the file was changed.
In debug output coming from document.c:monitor_file_changed_cb() I see
that CHANGE notification is sent twice after a file is saved. Maybe
it's g_file_replace_contents() which cause this, or it's a bug in my
GLib version, I don't know. I changed the code of the callback to
check mtime before setting doc->file_disk_status to CHANGE, and file
saving is now works correctly for me. If you think this change is
meaningful, consider the patch I attach. Apart of the change in the
callback it contains some other staff (which you may wish to not
commit).
Best regards,
Eugene.
diff --git a/src/document.c b/src/document.c
index 7155460..b3ff914 100644
--- a/src/document.c
+++ b/src/document.c
@@ -436,37 +436,56 @@ static void monitor_file_changed_cb(G_GNUC_UNUSED GFileMonitor *monitor, G_GNUC_
G_GNUC_UNUSED GFile *other_file, GFileMonitorEvent event,
GeanyDocument *doc)
{
- g_return_if_fail(doc != NULL);
+ const gchar* prev_status_name;
+ const gchar* event_name;
+ const gchar* status_name;
+ g_return_if_fail(doc != NULL);
if (file_prefs.disk_check_timeout == 0)
return;
- geany_debug("%s: event: %d previous file status: %d",
- G_STRFUNC, event, doc->priv->file_disk_status);
+ prev_status_name = file_disk_status_get_name(doc->priv->file_disk_status);
+
switch (event)
{
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
{
+ event_name = "CHANGED";
if (doc->priv->file_disk_status == FILE_IGNORE)
doc->priv->file_disk_status = FILE_OK;
- else
- doc->priv->file_disk_status = FILE_CHANGED;
- g_message("%s: FILE_CHANGED", G_STRFUNC);
+ else if (doc->priv->file_disk_status != FILE_CHANGED)
+ {
+ gboolean changed = TRUE;
+ gchar *locale_filename = utils_get_locale_from_utf8(doc->file_name);
+ struct stat st;
+ if (g_stat(locale_filename, &st) != 0)
+ g_warning("%s: Could not query mtime", G_STRFUNC);
+ else
+ changed = doc->priv->mtime < st.st_mtime;
+ g_free(locale_filename);
+
+ if (changed)
+ doc->priv->file_disk_status = FILE_CHANGED;
+ }
break;
}
case G_FILE_MONITOR_EVENT_DELETED:
{
+ event_name = "DELETED";
doc->priv->file_disk_status = FILE_CHANGED;
- g_message("%s: FILE_MISSING", G_STRFUNC);
break;
}
default:
+ event_name = "UNKNOWN";
break;
}
+
+ status_name = file_disk_status_get_name(doc->priv->file_disk_status);
+ geany_debug("%s: event: %s; status: %s -> %s",
+ G_STRFUNC, event_name, prev_status_name, status_name);
+
if (doc->priv->file_disk_status != FILE_OK)
- {
ui_update_tab_status(doc);
- }
}
#endif
@@ -780,10 +799,9 @@ GeanyDocument *document_new_file(const gchar *utf8_filename, GeanyFiletype *ft,
editor_goto_pos(doc->editor, 0, FALSE);
document_try_focus(doc, NULL);
+ doc->priv->mtime = time(NULL);
#if USE_GIO_FILEMON
monitor_file_setup(doc);
-#else
- doc->priv->mtime = time(NULL);
#endif
/* "the" SCI signal (connect after initial setup(i.e. adding text)) */
@@ -1473,7 +1491,6 @@ gboolean document_reload_file(GeanyDocument *doc, const gchar *forced_enc)
static gboolean document_update_timestamp(GeanyDocument *doc, const gchar *locale_filename)
{
-#if ! USE_GIO_FILEMON
struct stat st;
g_return_val_if_fail(doc != NULL, FALSE);
@@ -1488,7 +1505,6 @@ static gboolean document_update_timestamp(GeanyDocument *doc, const gchar *local
}
doc->priv->mtime = st.st_mtime; /* get the modification time from file and keep it */
-#endif
return TRUE;
}
@@ -3024,8 +3040,8 @@ gboolean document_check_disk_status(GeanyDocument *doc, gboolean force)
if (file_prefs.disk_check_timeout == 0 || doc->real_path == NULL || doc->priv->is_remote)
return FALSE;
+ cur_time = time(NULL);
use_gio_filemon = (doc->priv->monitor != NULL);
-
if (use_gio_filemon)
{
if (doc->priv->file_disk_status != FILE_CHANGED && ! force)
@@ -3033,10 +3049,8 @@ gboolean document_check_disk_status(GeanyDocument *doc, gboolean force)
}
else
{
- cur_time = time(NULL);
if (! force && doc->priv->last_check > (cur_time - file_prefs.disk_check_timeout))
return FALSE;
-
doc->priv->last_check = cur_time;
}
@@ -3047,8 +3061,7 @@ gboolean document_check_disk_status(GeanyDocument *doc, gboolean force)
/* doc may be closed now */
ret = TRUE;
}
- else if (! use_gio_filemon && /* ignore these checks when using GIO */
- (G_UNLIKELY(doc->priv->mtime > cur_time) || G_UNLIKELY(st.st_mtime > cur_time)))
+ else if (G_UNLIKELY(doc->priv->mtime > cur_time || st.st_mtime > cur_time))
{
g_warning("%s: Something is wrong with the time stamps.", G_STRFUNC);
}
@@ -3072,3 +3085,17 @@ gboolean document_check_disk_status(GeanyDocument *doc, gboolean force)
}
+const gchar* file_disk_status_get_name(FileDiskStatus status)
+{
+ switch(status)
+ {
+ case FILE_OK:
+ return "OK";
+ case FILE_CHANGED:
+ return "CHANGED";
+ case FILE_IGNORE:
+ return "IGNORE";
+ default:
+ return "UNKNOWN";
+ }
+}
diff --git a/src/documentprivate.h b/src/documentprivate.h
index babb874..025188f 100644
--- a/src/documentprivate.h
+++ b/src/documentprivate.h
@@ -87,4 +87,7 @@ typedef struct GeanyDocumentPrivate
}
GeanyDocumentPrivate;
+
+const gchar* file_disk_status_get_name(FileDiskStatus status);
+
#endif
_______________________________________________
Geany-devel mailing list
Geany-devel@uvena.de
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel