Autosave

Bug #171092 reported by Bmud
76
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Inkscape
Fix Released
Medium
Jon A. Cruz

Bug Description

So, I just lost a really nice document. The recovery
during the error failed...and I'm not sure that its
ever been successful. How about a periodic autosave option?

Revision history for this message
Jon A. Cruz (jon-joncruz) wrote :

Closing "[ 1488110 ] Make document autosave work on any crash" as a dup of

this one.
http://sourceforge.net/tracker/index.php?
func=detail&aid=1488110&group_id=93438&atid=604309

Revision history for this message
Tinarussell-users (tinarussell-users) wrote :

Originator: NO

Please please please add this feature. Please please please. It's in every
other program I use and it cuts down my blood pressure by about 90%. I've
used computers long enough to have the obsessive-compulsive Ctrl-S habit,
but we are long past the days in which that should still be necessary. Just
now I was relieved to find that a file I was working on before my compy
crashed was saved just prior, so it made it through without a scratch... it
just chills me to think of what if I hadn't remembered to save. I know that
Every Good Computer User(TM) saves absolutely constantly, but that kind of
jittery, worried twitch should have ceased to be compulsory long, long ago.
At least put something in the options menu, please, please, please.

(I have my computer do daily, automatic backups to a different hard disk
for just this reason... it really takes a collossal amount of pressure off
of me and allows me to do my work much more effectively. But, backup
programs don't help for what's in RAM... so please, please, please somebody
add an autosave feature to Inkscape. Please, please, please. Thanks.)

Revision history for this message
Kur9kin (kur9kin) wrote :
Download full text (11.7 KiB)

Originator: NO

Here's a patch that implements autosaves.

Added to the preferences dialog is settings for
enabling the autosave-feature, setting interval,
where to save the files, and how many files to save.

The reason for being able to save many files, is so that
a user can "timetravel", and get a document from say a couple of
hours ago.

I had to put the code in inkscape.cpp, since I wanted to get access
to the document-list in Inkscape::Application. Any ideas on how to
do this differently?

Also, I havent put much effort into the preferences-dialog.
For example, as of now, any changes will only become active after a
restart of inkscape. Also, when disabling autosave, a grey-out of
the other widgets would be nice.

Well... Since I can't create attachments, I'll just paste the diff here:
(against rev.16434)

-BEGIN--autosave.diff--------
Index: src/inkscape.cpp
===================================================================
--- src/inkscape.cpp (revision 16434)
+++ src/inkscape.cpp (working copy)
@@ -41,6 +41,8 @@

 #include <gtk/gtkmain.h>
 #include <gtk/gtkmessagedialog.h>
+#include <glib.h>
+#include <glib/gstdio.h>

 #include <glibmm/i18n.h>
 #include "helper/sp-marshal.h"
@@ -59,8 +61,12 @@
 #include "prefs-utils.h"
 #include "xml/repr.h"
 #include "io/sys.h"
+#include "message-stack.h"

 #include "extension/init.h"
+#include "extension/db.h"
+#include "extension/output.h"
+#include "extension/system.h"

 static Inkscape::Application *inkscape = NULL;

@@ -285,7 +291,135 @@
     klass->deactivate_desktop = inkscape_deactivate_desktop_private;
 }

+/* static gint inkscape_autosave(gpointer);
+ *
+ * Callback passed to g_timeout_add_seconds()
+ * Responsible for autosaving all open documents
+ */
+static gint inkscape_autosave(gpointer)
+{
+ uid_t uid;
+ const gchar *autosave_dir;
+ GDir *autosave_dir_ptr;

+ /* Use UID for separating autosave-documents between users if
directory is multiuser*/
+ uid = getuid();
+
+ autosave_dir = prefs_get_string_attribute("options.autosave",
"path");
+ if( autosave_dir == NULL )
+ autosave_dir = "/tmp";
+
+ autosave_dir_ptr = g_dir_open(autosave_dir, 0, NULL);
+ if( autosave_dir_ptr == NULL ){
+ fprintf(stderr, "Cannot open autosave directory!\n");
+ return TRUE;
+ }
+
+ time_t sptime = time (NULL);
+ struct tm *sptm = localtime (&sptime);
+ gchar sptstr[256];
+ strftime (sptstr, 256, "%Y_%m_%d_%H_%M_%S", sptm);
+
+ SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE,
_("Autosaving documents..."));
+ for( std::multiset<SPDocument*>::iterator it =
inkscape->document_set.begin(); it != inkscape->document_set.end(); it++
){
+ SPDocument *doc;
+ Inkscape::XML::Node *repr;
+ doc = (SPDocument *) *it;
+
+ repr = sp_document_repr_root (doc);
+ if (repr->attribute("sodipodi:modified")) {
+ gchar c[1024];
+ gchar full_path[1024];
+ gchar *oldest_autosave = NULL;
+ const gchar *filename;
+ struct stat sb;
+ time_t min_tv_sec = 0;
+ gint count = 0;
+
+
+ /* Look for previous autosaves */
+ ...

Revision history for this message
Alexandre Prokoudine (alexandre-prokoudine) wrote :

Kur9kin, many thanks for your patch! We'll definitely have a look at it to find out which part of it needs improvements and if we can make it part of upcoming 0.46.

Changed in inkscape:
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Jon A. Cruz (jon-joncruz) wrote :

First step is cleaning up the patch.

I *think* I got the web stuff cleaned out properly.

Revision history for this message
Jon A. Cruz (jon-joncruz) wrote :

Cleaned up, de-webified patch

Bryce Harrington (bryce)
Changed in inkscape:
milestone: none → 0.46
Revision history for this message
bbyak (buliabyak) wrote :

Tried to compile, got error:

inkscape.cpp: In function 'gint inkscape_autosave(void*)':
inkscape.cpp:347: error: 'struct stat' has no member named 'st_ctimespec'
inkscape.cpp: In function 'void inkscape_autosave_init()':
inkscape.cpp:400: warning: converting negative value '-0x00000000000000001' to 'guint32'
inkscape.cpp:403: warning: comparison between signed and unsigned integer expressions
inkscape.cpp:409: warning: converting negative value '-0x00000000000000001' to 'guint32'

please fix this so we can consider your patch

Revision history for this message
bbyak (buliabyak) wrote :

(i used joncruz' cleaned up patch, please work from it)

Revision history for this message
Bryce Harrington (bryce) wrote :

We could consider including this disabled by default; since we're short on testing time I'm a bit concerned about including it enabled for everyone, as it might have some unpredictable effects (like interrupting workflow with save operations every so many minutes).

Revision history for this message
username132 (sean-van-der-smythe) wrote :

Just lost my work :'( I don't know how to vote for this bug/enhancement so I'm leaving a comment to say "+1"!

Revision history for this message
Tom Davidson (tjd-mit) wrote :

Marked bug 170167 as a dupe -- there is a log of an IRC discussion between Ted, Mental, Bryce and JonCrux there with some discussion about implementation.

Revision history for this message
Bryce Harrington (bryce) wrote :

We're running low on time to get this implemented. We need to get something committable asap and/or make a decision on it.

Revision history for this message
MenTaLguY (mental-deactivatedaccount) wrote :

I don't think there's time to implement a robust autosave before the release, given some of the issues which I raised in the IRC conversation.

I think fixing the emergency save would be feasible, though.

Revision history for this message
MenTaLguY (mental-deactivatedaccount) wrote :

Actually, fixing emergency save would probably cover most of the use cases that people want autosave for too.

Revision history for this message
Bryce Harrington (bryce) wrote :

Sounds good. Moving milestone to 0.47.

Changed in inkscape:
milestone: 0.46 → 0.47
Revision history for this message
Sini Ruohomaa (kataja) wrote :

Feature request #182937 is also saving-related. https://bugs.launchpad.net/inkscape/+bug/182937

Revision history for this message
Alexandre Prokoudine (alexandre-prokoudine) wrote :

Do we want this for 0.47? :)

Revision history for this message
bbyak (buliabyak) wrote :

so can the author please resubmit this patch making sure it applies to current svn?

Revision history for this message
MenTaLguY (mental-deactivatedaccount) wrote :

Two things:

1. sodipodi:modified is gone now; the patch will need to take that into account

2. This will introduce an "Inkscape periodically freezes for short periods of time when large documents are being edited" bug.

With respect to the second, I don't think we should implement autosave until we have sufficient infrastructure to allow it to work without disruption of the user's editing. That means:

1. XML::Document needs to be made threadsafe
2. There needs to be the ability to take a threadsafe copy-on-write "snapshot" of the XML tree
3. Autosave would acquire such snapshots of all the modified documents and then write them to disk from a separate thread.

Revision history for this message
bbyak (buliabyak) wrote : Re: [Bug 171092] Re: Autosave

On Thu, Mar 27, 2008 at 1:46 PM, MenTaLguY <email address hidden> wrote:
> 2. This will introduce an "Inkscape periodically freezes for short
> periods of time when large documents are being edited" bug.

Just make it off by default, so that whoever turns it on know what to expect.

> With respect to the second, I don't think we should implement autosave
> until we have sufficient infrastructure to allow it to work without
> disruption of the user's editing. That means:
>
> 1. XML::Document needs to be made threadsafe
> 2. There needs to be the ability to take a threadsafe copy-on-write "snapshot" of the XML tree
> 3. Autosave would acquire such snapshots of all the modified documents and then write them to disk from a separate thread.

That sounds like a tall order. Would be nice to have of course, but I
don't think we should postpone any autosave functionality until this
is done. Inkscape saves are reasonably fast even for huge documents.

Revision history for this message
jack_spratt (jack-spratt) wrote :

I'm absolutely desperate for the autosave to be implemented - every time I use the app I lose work, often hours, due to infrequent saves. I've set alarms etc but sometimes that isn't practical or possible. The emergency crash feature is usually good, but when running on windows its not inkscape that causes the crashes, the system just goes down with BSODs or something for no reason, as windows does, and there's no way of retrieving work! Please please please implement auto save; what can I do to help get this added? I already donated, I don't know code..

Revision history for this message
Ulferikson (ulferikson) wrote :

Here is an update to Kur9kin's patch that compiles for me. Due to Bug #173116 (Win32: Unable to catch exceptions thrown by dll's) I've seen Inkscape go down too often without emergency backups lately..

Revision history for this message
bbyak (buliabyak) wrote :

mental, are you still opposed to it? i would like to test and commit it if it works

Revision history for this message
MenTaLguY (mental-deactivatedaccount) wrote :

I think I can live with it if it's off by default. The XML changes I
just made recently were actually groundwork for (among other things) the
"snapshot" capability that I think is required to implement this without
causing UI lag problems.

Revision history for this message
Jon A. Cruz (jon-joncruz) wrote :

I'm going through a cleanup pass on it now. Among other issues it does have a lot of copy-n-paste legacy C stuff we'll want to avoid. Plus I'm trying to get better naming/location.

Changed in inkscape:
status: Confirmed → In Progress
Revision history for this message
Jon A. Cruz (jon-joncruz) wrote :

A significantly cleaned up version has now been committed.

Changed in inkscape:
status: In Progress → Fix Released
Revision history for this message
Thebugfinder (incessantblabber) wrote :

Please please PLEASE add this, and quickly! Thank you!

Revision history for this message
Alexandre Prokoudine (alexandre-prokoudine) wrote :

@Thebugfinder

It was committed on June 12. Do you mean you want us to commit it once again? :-)))))

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.