After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 574376 - Save doesn't always save
Save doesn't always save
Status: RESOLVED FIXED
Product: anjuta
Classification: Applications
Component: plugins: editor: gtksourceview
2.25.x
Other All
: Normal blocker
: ---
Assigned To: Johannes Schmid
Anjuta maintainers
Depends on:
Blocks:
 
 
Reported: 2009-03-06 15:03 UTC by John
Modified: 2009-03-18 08:07 UTC
See Also:
GNOME target: ---
GNOME version: 2.23/2.24


Attachments
Finish all save operations before exit(1) (14.17 KB, patch)
2009-03-15 15:53 UTC, Johannes Schmid
none Details | Review
Cleaned patch (8.18 KB, patch)
2009-03-15 19:01 UTC, Johannes Schmid
committed Details | Review
Backport to 2.24.x (7.50 KB, patch)
2009-03-16 17:49 UTC, Debarshi Ray
reviewed Details | Review

Description John 2009-03-06 15:03:22 UTC
Please describe the problem:
When trying to exit, without saving first, any changes are detected correctly,
and the save dialog appears. It seems however, that pressing 'Save' doesn't
save correctly.

Steps to reproduce:
1. Open an existing file
2. Modify the file typing a couple of letters
3. Click on the 'close' (X top right) button
4. The Save dialog appears - click on Save


Actual results:
The last changes are _not_ saved. After reopening, the changes are not there

Expected results:
Find the last changes on disk

Does this happen every time?
Yes

Other information:
Comment 1 Johannes Schmid 2009-03-06 16:00:56 UTC
Thanks for reporting. I can imaging that this happens because the "saver" object is destroyed before saving finishes. I will have a look this weekend!

I guess you are using the gtksourceview editor?
Comment 2 John 2009-03-06 16:47:40 UTC
Yes. Sorry, I should have mentioned that. I guess this could be the reason for the infrequent crashes on exit too? Didn't report that because it happens only once a week or so.

GtkSourceView works quite well. There's only one thing I really hate: When copying the 'old' way, with just the mouse (paint + middle button paste), the cursor always jumps back to the original location, which is very annoying. But I guess I'll have complain to the GtkSourceView people about that.

John
Comment 3 Johannes Schmid 2009-03-09 08:46:52 UTC
I made some changes but I cannot reproduce the bug here. I would be great if you could retry this with latest trunk. Thanks!
Comment 4 John 2009-03-12 15:24:51 UTC
I updated to svn 4852, and no change. I tried several times, and, as documented before, the 'Changed' dialog appears, but clicking on 'Save' doesn't do it. 

It would be less annoying if a 'Save All' option would exist under 'Files'. After editing several files, the only way to assure saving is go to each and save them one by one.

The following warnings do come out (I believe they weren't there before) on the console:

(anjuta:13848): Gdl-WARNING **: Should not reach here: gdl_dock_select_larger_item:1132

(repeats 4 times).

There is also this warning, but it _was_ there before. I suspect it's because I have no macros defined:

I/O warning : failed to load external entity "/root/.local/share/anjuta/macro.xml"

John
Comment 5 Johannes Schmid 2009-03-12 17:50:14 UTC
Hmm, I cannot reproduce this here and the warnings look really unrelated.

BTW, there is a "Save all" option in the "Documents" menu.
Comment 6 Debarshi Ray 2009-03-12 22:24:22 UTC
I can reproduce this with SVN trunk.
Comment 7 Debarshi Ray 2009-03-12 22:30:29 UTC
(In reply to comment #1)

> I guess you are using the gtksourceview editor?
 
The problem appears to be present only in the GtkSourceView editor. The Scintilla editor did not pose any problems.
Comment 8 Debarshi Ray 2009-03-13 05:25:36 UTC
The asynchronous write (ie. g_output_stream_write_async) in sourceview_io_save_as is the problem here. Anjuta exits before the on_save_finished callback gets invoked. Using a blocking write (ie. g_output_stream_write) solves the problem.
Comment 9 Johannes Schmid 2009-03-13 07:52:06 UTC
Ah ok, sorry. I though you were refering to clicking on the "Close"-Button of an editor and not exiting the whole application. Hmm, that's indeed a bit tricky because we want async write operations of course as anything else would block the UI unnecessary long.

I will try to think of a solution for it.
Comment 10 John 2009-03-13 15:16:37 UTC
Anjuta takes 5 - 6 seconds to load on my machine. On exit, I wouldn't mind waiting for 1/2 second to be sure _all_ the source files are safely stored on disk.

In fact, thinking back, this behaviour explains why I had entire swatches of source code disappear earlier. It's amazing how much you can type in 10 minutes between autosaves.

How about the suggestion to change the behaviour of the 'Save' toolbutton, to make it save all changes (or add another one)? Even Turbo C/Pascal had a Save All option.

Comment 11 Johannes Schmid 2009-03-13 15:33:00 UTC
> How about the suggestion to change the behaviour of the 'Save' toolbutton, to
> make it save all changes (or add another one)? Even Turbo C/Pascal had a Save
> All option.

As I said in comment #2, this option exists in the Documents menu (or with the shortcut Shift-Ctrl-L).

Anyway, I am working on solving the issue by flushing all buffers but I couldn't figure out how to do this yet. Time is limited until Monday but I hope to be able to fix it before 2.26.0.

Comment 12 John 2009-03-13 15:56:09 UTC
> As I said in comment #2, this option exists in the Documents menu (or with the
> shortcut Shift-Ctrl-L).

I humbly apologize for missing that. This is one of those weeks. University started again, 7 more hours of teaching, a utility transformer blew up and so did my UPS, fax, phone, and scanner. Still repairing...

I would have expected file related commands to be under 'File' though.

Thanks,
John
Comment 13 Debarshi Ray 2009-03-13 19:07:56 UTC
Not that I am in favour of using blocking I/O calls, but it looks like the Scintilla editor plugin uses g_output_stream_write_all in the save_to_file function at plugins/scintilla/text_editor.c:1556

I was looking at how GEdit handles this, and found that they iterate through a list of files, and once the asynchronous write completion callback for the last file is invoked a signal is emitted to close the application.
Comment 14 Johannes Schmid 2009-03-15 15:53:42 UTC
Created attachment 130702 [details] [review]
Finish all save operations before exit(1)

This patch fixes the issue by waiting for all async operations that are propagated by anjuta_shell_saving_push/pop() before exiting.

Asking for release-team approval...
Comment 15 Debarshi Ray 2009-03-15 16:09:49 UTC
Any chance for a 2.24.x release with this fix?
Comment 16 John 2009-03-15 16:12:54 UTC
Thanks Johannes, applied the patch, recompiled - works fine. I feel a lot safer!

John
Comment 17 Johannes Schmid 2009-03-15 18:55:10 UTC
(In reply to comment #15)
> Any chance for a 2.24.x release with this fix?
>

No, I don't think so. We will release 2.26.0 on Wednesday and this will be our new stable series. If you need to maintain 2.24.x for other reasons in your distribution you can backport the patch and apply it to your package. (If you have problems with backporting I can have a look, too). 

Comment 18 Johannes Schmid 2009-03-15 19:01:53 UTC
Created attachment 130705 [details] [review]
Cleaned patch

The last patch contained some unrelated changes in the git plugin and in the htdocs that were unintended. This patch is now clean though it still contains the move from GOutputStream to g_file_replace_contents_async because I think that this is useful.

Thanks John for testing though this is 100%-reproducible for me without the patch!
Comment 19 Debarshi Ray 2009-03-15 21:51:32 UTC
Minor issue:

+/**
+ * anjuta_shell_saving_push:
+ * @shell: A #AnjutaShell interface
+ *
+ * Decrease the count of files that need to be saved 
+ *
+ */
+void anjuta_shell_saving_pop	    (AnjutaShell* shell)

The comment should be 'anjuta_shell_saving_pop'.
Comment 20 Debarshi Ray 2009-03-15 22:31:57 UTC
(In reply to comment #18)

Isn't g_cond_* a better way of doing this?
Comment 21 Johannes Schmid 2009-03-15 22:48:49 UTC
No, a GCond could help if we were using multiple threads. It's a gio implementation details how it does the async io - we just know when it's finished and this is all done within the main loop (in the main thread) when the "finished" signal is emitted.

You can see in the patch that I don't use a mutex for the save_count because it's only accessed by one thread. I kind of thought that there might be a method to ask gio to finish all async operations but that doesn't seem to exist.
Comment 22 Debarshi Ray 2009-03-16 17:49:50 UTC
Created attachment 130767 [details] [review]
Backport to 2.24.x
Comment 23 Debarshi Ray 2009-03-16 17:50:39 UTC
(In reply to comment #21)
> No, a GCond could help if we were using multiple threads. It's a gio
> implementation details how it does the async io - we just know when it's
> finished and this is all done within the main loop (in the main thread) when
> the "finished" signal is emitted.

Okay, I had the wrong idea that the callback would get invoked from a separate thread.

Could you please have a look at the backported patch against 2.24.x?
Comment 24 Johannes Schmid 2009-03-16 18:35:11 UTC
Looks good - were there any changes besides line numbers?
Comment 25 Debarshi Ray 2009-03-16 18:59:17 UTC
(In reply to comment #24)

> Looks good - were there any changes besides line numbers?

sourceview-io.c seemed to have some changes over the 2.24.x version.