[almanah/almanah-0-6: 1/5] Only delete the plaintext database file if the encrypted database file's
- From: Philip Withnall <pwithnall src gnome org>
- To: svn-commits-list gnome org
- Subject: [almanah/almanah-0-6: 1/5] Only delete the plaintext database file if the encrypted database file's
- Date: Mon, 1 Jun 2009 05:29:24 -0400 (EDT)
commit 4cba78e8d2b5966527403c493486906e4acd47a3
Author: Philip Withnall <philip tecnocode co uk>
Date: Mon Jun 1 10:04:44 2009 +0100
Only delete the plaintext database file if the encrypted database file's
2009-01-29 Philip Withnall <philip tecnocode co uk>
* src/storage-manager.c (database_idle_cb), (encrypt_database):
Only delete the plaintext database file if the encrypted
database
file's size is greater than 0B, to try and prevent data loss in
odd situations.
svn path=/trunk/; revision=135
---
ChangeLog | 7 +++++++
src/storage-manager.c | 24 +++++++++++++++---------
2 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 90cb5c4..3b8c756 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-01-29 Philip Withnall <philip tecnocode co uk>
+
+ * src/storage-manager.c (database_idle_cb), (encrypt_database):
+ Only delete the plaintext database file if the encrypted database
+ file's size is greater than 0B, to try and prevent data loss in
+ odd situations.
+
============ Version 0.6.0
2009-01-27 Philip Withnall <philip tecnocode co uk>
diff --git a/src/storage-manager.c b/src/storage-manager.c
index 883c72c..7e9ffaf 100644
--- a/src/storage-manager.c
+++ b/src/storage-manager.c
@@ -305,12 +305,26 @@ cipher_operation_free (CipherOperation *operation)
static gboolean
database_idle_cb (CipherOperation *operation)
{
+ AlmanahStorageManager *self = operation->storage_manager;
gpgme_error_t gpgme_error;
if (!(gpgme_wait (operation->context, &gpgme_error, FALSE) == NULL && gpgme_error == 0)) {
+ struct stat db_stat;
+
+ /* Check to see if the encrypted file is 0B in size, which isn't good.
+ * Not much we can do about it except quit without deleting the plaintext database. */
+ g_stat (self->priv->filename, &db_stat);
+ if (g_file_test (self->priv->filename, G_FILE_TEST_IS_REGULAR) == FALSE || db_stat.st_size == 0) {
+ g_warning (_("Error encrypting database: %s"),
+ _("The encrypted database is empty. The plain database file has been left undeleted as backup."));
+ } else if (g_unlink (self->priv->plain_filename) != 0) {
+ /* Delete the plain file */
+ g_warning (_("Could not delete plain database file \"%s\"."), self->priv->plain_filename);
+ }
+
/* A slight assumption that we're disconnecting at this point (we're technically
* only encrypting), but a valid one. */
- g_signal_emit (operation->storage_manager, storage_manager_signals[SIGNAL_DISCONNECTED], 0, operation->storage_manager);
+ g_signal_emit (self, storage_manager_signals[SIGNAL_DISCONNECTED], 0, self);
/* Finished! */
cipher_operation_free (operation);
@@ -407,14 +421,6 @@ encrypt_database (AlmanahStorageManager *self, const gchar *encryption_key, GErr
/* The operation will be completed in the idle function */
g_idle_add ((GSourceFunc) database_idle_cb, operation);
- /* Delete the plain file and wait for the idle function to quit us */
- if (g_unlink (self->priv->plain_filename) != 0) {
- g_set_error (error, ALMANAH_STORAGE_MANAGER_ERROR, ALMANAH_STORAGE_MANAGER_ERROR_ENCRYPTING,
- _("Could not delete plain database file \"%s\"."),
- self->priv->plain_filename);
- return FALSE;
- }
-
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]