[almanah/almanah-0-6: 2/5] Added some missing #includes. Make an automatic backup of the database



commit fac44379398035ed8cabaec72d1bb76b1cc48faa
Author: Philip Withnall <philip tecnocode co uk>
Date:   Mon Jun 1 10:08:00 2009 +0100

    Added some missing #includes. Make an automatic backup of the database
    
    2009-03-01  Philip Withnall  <philip tecnocode co uk>
    
    	* src/main-window.c: Added some missing #includes.
    	* src/storage-manager.c (back_up_file),
    	(almanah_storage_manager_connect): Make an automatic backup of the
    	database before opening it just to be safe. (Closes: #572926)
    
    svn path=/trunk/; revision=140
---
 ChangeLog             |    7 +++++++
 src/main-window.c     |    2 ++
 src/storage-manager.c |   26 ++++++++++++++++++++++++--
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3b8c756..8a47389 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-03-01  Philip Withnall  <philip tecnocode co uk>
+
+	* src/main-window.c: Added some missing #includes.
+	* src/storage-manager.c (back_up_file),
+	(almanah_storage_manager_connect): Make an automatic backup of the
+	database before opening it just to be safe. (Closes: #572926)
+
 2009-01-29  Philip Withnall  <philip tecnocode co uk>
 
 	* src/storage-manager.c (database_idle_cb), (encrypt_database):
diff --git a/src/main-window.c b/src/main-window.c
index 4112d88..33e88a1 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -30,6 +30,8 @@
 #include "main.h"
 #include "interface.h"
 #include "add-definition-dialog.h"
+#include "preferences-dialog.h"
+#include "search-dialog.h"
 #include "printing.h"
 #include "entry.h"
 #include "storage-manager.h"
diff --git a/src/storage-manager.c b/src/storage-manager.c
index 7e9ffaf..3d0ab13 100644
--- a/src/storage-manager.c
+++ b/src/storage-manager.c
@@ -454,6 +454,24 @@ get_encryption_key (void)
 }
 #endif /* ENABLE_ENCRYPTION */
 
+static void
+back_up_file (const gchar *filename)
+{
+	GFile *original_file, *backup_file;
+	gchar *backup_filename;
+
+	/* Make a backup of the encrypted database file */
+	original_file = g_file_new_for_path (filename);
+	backup_filename = g_strdup_printf ("%s~", filename);
+	backup_file = g_file_new_for_path (backup_filename);
+	g_free (backup_filename);
+
+	g_file_copy_async (original_file, backup_file, G_FILE_COPY_OVERWRITE, G_PRIORITY_DEFAULT, NULL, NULL, NULL, NULL, NULL);
+
+	g_object_unref (original_file);
+	g_object_unref (backup_file);
+}
+
 gboolean
 almanah_storage_manager_connect (AlmanahStorageManager *self, GError **error)
 {
@@ -467,6 +485,9 @@ almanah_storage_manager_connect (AlmanahStorageManager *self, GError **error)
 	if (g_file_test (self->priv->filename, G_FILE_TEST_IS_REGULAR) == TRUE && encrypted_db_stat.st_size > 0) {
 		GError *child_error = NULL;
 
+		/* Make a backup of the encrypted database file */
+		back_up_file (self->priv->filename);
+
 		g_stat (self->priv->plain_filename, &plaintext_db_stat);
 
 		/* Only decrypt the database if the plaintext database doesn't exist or is empty. If the plaintext
@@ -484,12 +505,13 @@ almanah_storage_manager_connect (AlmanahStorageManager *self, GError **error)
 				g_error_free (child_error);
 			}
 		}
-
-		
 	}
 
 	self->priv->decrypted = TRUE;
 #else
+	/* Make a backup of the plaintext database file */
+	back_up_file (self->priv->plain_filename);
+
 	self->priv->decrypted = FALSE;
 #endif /* ENABLE_ENCRYPTION */
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]