|
From: Raphaël D. <rap...@gm...> - 2014-05-08 17:17:44
|
Hi, attached is a tricky patch: It skip database rewrites to disk when no changes actually happened. The current issue is that there is no locking/notify mechanism for the database file and, especially if using autosave=true, multiple abook instances imply that "latest closed wins". Reproducer: - term1 run abook - term2 run mutt, add an email (trigger abook --add-email) # here datafile is changed on disk with the new email - close abook in term1 # here datafile is changed on disk, the email is lost There are several ways to avoid/warn when this happens, but all of them first needs that we avoid file rewrites when no change happened, that means isolating write operations. Currently: $ ls -i .abook/addressbook 8535 .abook/addressbook $ abook # press "q" to quit $ ls -i .abook/addressbook 7943 .abook/addressbook This is what the patch attempts to solve by marking the database "need save" after (every) "write" operation on items. That allowed adding a "*" indicator à la emacs to show the "db modified" status. The more sensible here is to ensure that *every* possible action implying modification of the database will really triggers db_need_save = TRUE. If some are missing from the patch the related modifications will *not* be saved to disk. That is to say that this patch has to be *sure*. I need to think more about the behavior when autosave=false but IHMO the check for "is db modified" must be activated for all *saving* vectors, that means that pressing "w" to explicitly save the database to disk will *not* rewrite if there is no modification. I tried many (if not all) of the possible operations offered by the UI and hope to not have missed any. But as shown by the hunk affecting edit.c, database write operations are not strictly restricted to database.c. Further testing welcome. Next I'd see a more robust way to handle concurrent write accesses to datafile. I can think about file-lock and inotify and I'd rather want to avoid any need of datafile "merge". regards -- GPG id: 0xD7F62B21 |