* 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
This commit is contained in:
Derek Atkins 2002-10-24 13:28:44 +00:00
parent 7fd929c6a4
commit 111939ef7e
2 changed files with 17 additions and 7 deletions

View File

@ -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 <derek@ihtfp.com>
Fix a bunch of compiler warnings:
* Transaction-matcher.c: use "=" not "==" to set a variable

View File

@ -602,19 +602,26 @@ gnc_file_be_remove_old_files(FileBackend *be)
(stat(name, &statbuf) == 0) &&
(statbuf.st_mtime <lockstatbuf.st_mtime)) {
unlink(name);
} else if (file_retention_days != 0) {
} else if (file_retention_days > 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);