From 111939ef7eabfb9c6fd254d94f9d43c447252cee Mon Sep 17 00:00:00 2001 From: Derek Atkins Date: Thu, 24 Oct 2002 13:28:44 +0000 Subject: [PATCH] * gnc-backend-file.c: make sure a file HAS a date before actually removing it. Otherwise you will remove a foo.xac file by accident. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7380 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 3 +++ src/backend/file/gnc-backend-file.c | 21 ++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index c098035bc1..a66a724e43 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,9 @@ or the lookups fail when adding new menus. In particular, "_Actions", "_Toolbar", and "_Status Bar". + * gnc-backend-file.c: make sure a file HAS a date before actually + removing it. Otherwise you will remove a foo.xac file by accident. + 2002-10-22 Derek Atkins Fix a bunch of compiler warnings: * Transaction-matcher.c: use "=" not "==" to set a variable diff --git a/src/backend/file/gnc-backend-file.c b/src/backend/file/gnc-backend-file.c index ec92a2df81..97acad43d4 100644 --- a/src/backend/file/gnc-backend-file.c +++ b/src/backend/file/gnc-backend-file.c @@ -602,19 +602,26 @@ gnc_file_be_remove_old_files(FileBackend *be) (stat(name, &statbuf) == 0) && (statbuf.st_mtime 0) { time_t file_time; struct tm file_tm; int days; + const char* res; /* Is the backup file old enough to delete */ memset(&file_tm, 0, sizeof(file_tm)); - strptime(name+pathlen+1, "%Y%m%d%H%M%S", &file_tm); - file_time = mktime(&file_tm); - days = (int)(difftime(now, file_time) / 86400); - if (days > file_retention_days) { - unlink(name); - } + res = strptime(name+pathlen+1, "%Y%m%d%H%M%S", &file_tm); + file_time = mktime(&file_tm); + days = (int)(difftime(now, file_time) / 86400); + + /* Make sure this file actually has a date before unlinking */ + if (res && res != name+pathlen+1 && + /* We consumed some but not all of the filename */ + file_time > 0 && + /* we actually have a reasonable time and it is old enough */ + days > file_retention_days) { + unlink(name); + } } } g_free(name);