almanah r140 - in trunk: . src



Author: pwithnall
Date: Sun Mar  1 21:15:58 2009
New Revision: 140
URL: http://svn.gnome.org/viewvc/almanah?rev=140&view=rev

Log:
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)



Modified:
   trunk/ChangeLog
   trunk/src/main-window.c
   trunk/src/storage-manager.c

Modified: trunk/src/main-window.c
==============================================================================
--- trunk/src/main-window.c	(original)
+++ trunk/src/main-window.c	Sun Mar  1 21:15:58 2009
@@ -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"

Modified: trunk/src/storage-manager.c
==============================================================================
--- trunk/src/storage-manager.c	(original)
+++ trunk/src/storage-manager.c	Sun Mar  1 21:15:58 2009
@@ -454,6 +454,24 @@
 }
 #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 @@
 	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 @@
 				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]