This patch built from upstream svn changesets 6446, 6828 and 6829.
Index: src/file_autosave.c
===================================================================
--- src/file_autosave.c (revision 6439)
+++ src/file_autosave.c (working copy)
@@ -178,9 +178,12 @@
/* cancel running autosave */
if (doc->autosave_progress) {
- file_checkNsave_cancel(doc->autosave_action);
- main_v->autosave_progress = g_list_delete_link(main_v->autosave_progress, doc->autosave_progress);
- doc->autosave_progress = NULL;
+ if (doc->autosave_action) {
+ file_checkNsave_cancel(doc->autosave_action);
+ doc->autosave_action = NULL;
+ }
+ main_v->autosave_progress = g_list_delete_link(main_v->autosave_progress, doc->autosave_progress);
+ doc->autosave_progress = NULL;
}
if (doc->autosave_uri) {
Index: src/file.c
===================================================================
--- src/file.c (revision 6827)
+++ src/file.c (revision 6829)
@@ -401,7 +401,10 @@
g_file_replace_contents_finish(cns->uri,res,&etag,&error);
if (error) {
DEBUG_MSG("checkNsave_replace_async_lcb,error %d: %s\n",error->code,error->message);
- if (error->code == G_IO_ERROR_WRONG_ETAG) {
+ if (error->code == G_IO_ERROR_CANCELLED) {
+ cns->callback_func(CHECKANDSAVE_ERROR_CANCELLED, error, cns->callback_data);
+ checkNsave_cleanup(cns);
+ } else if (error->code == G_IO_ERROR_WRONG_ETAG) {
if (cns->callback_func(CHECKANDSAVE_ERROR_MODIFIED,error, cns->callback_data) == CHECKNSAVE_CONT) {
g_file_replace_contents_async(cns->uri,cns->buffer->data,cns->buffer_size
,NULL,TRUE
@@ -467,12 +470,25 @@
checkNsave_cleanup(cns);
}
-void file_checkNsave_cancel(gpointer cns) {
- g_cancellable_cancel(((TcheckNsave *)cns)->cancelab);
+void file_checkNsave_cancel(gpointer data) {
+ TcheckNsave *cns = data;
+ if (!cns)
+ return;
+ /* if the checkNsave is still on the queue, and not yet started, the cancellable is NULL
+ and we should remove it from the queue */
+ if (cns->cancelab) {
+ g_cancellable_cancel(cns->cancelab);
+ return;
+ }
+ queue_remove(&sfqueue, cns);
+ cns->callback_func(CHECKANDSAVE_ERROR_CANCELLED, NULL, cns->callback_data);
+ checkNsave_cleanup(cns);
+ return;
}
static void file_checkNsave_run(gpointer data) {
TcheckNsave *cns=data;
+ cns->cancelab = g_cancellable_new();
g_file_replace_contents_async(cns->uri,cns->buffer->data,cns->buffer_size
,cns->etag,cns->backup
,G_FILE_CREATE_NONE,cns->cancelab
@@ -482,7 +498,6 @@
gpointer file_checkNsave_uri_async(GFile *uri, GFileInfo *info, Trefcpointer *buffer, gsize buffer_size, gboolean check_modified, gboolean backup, CheckNsaveAsyncCallback callback_func, gpointer callback_data) {
TcheckNsave *cns;
cns = g_slice_new0(TcheckNsave);
- cns->cancelab = g_cancellable_new();
/*cns->etag=NULL;*/
cns->callback_data = callback_data;
cns->callback_func = callback_func;