From 3e7e29f5f502f466470b8673870c71fd32304368 Mon Sep 17 00:00:00 2001 From: gardners Date: Mon, 3 Dec 2012 12:20:50 +1030 Subject: [PATCH] improve handling of incomplete files in rhizome database (clean all out on start up, but only clean out specific ones when inserting). --- rhizome_database.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rhizome_database.c b/rhizome_database.c index fac8f12e..0e398a17 100644 --- a/rhizome_database.c +++ b/rhizome_database.c @@ -224,6 +224,7 @@ int rhizome_opendb() sqlite_exec_void_loglevel(LOG_LEVEL_WARN, "DELETE FROM FILES WHERE NOT EXISTS( SELECT 1 FROM MANIFESTS WHERE MANIFESTS.filehash = FILES.id);"); sqlite_exec_void_loglevel(LOG_LEVEL_WARN, "DELETE FROM MANIFESTS WHERE filehash != '' AND NOT EXISTS( SELECT 1 FROM FILES WHERE MANIFESTS.filehash = FILES.id);"); RETURN(0); + sqlite_exec_void("DELETE FROM FILES WHERE datavalid=0;"); } int rhizome_close_db() @@ -1019,7 +1020,7 @@ int rhizome_store_file(rhizome_manifest *m,const unsigned char *key) /* Okay, so there are no records that match, but we should delete any half-baked record (with datavalid=0) so that the insert below doesn't fail. Don't worry about the return result, since it might not delete any records. */ - sqlite_exec_void("DELETE FROM FILES WHERE datavalid=0;"); + sqlite_exec_void("DELETE FROM FILES WHERE in='%s' AND datavalid=0;",hash); /* INSERT INTO FILES(id as text, data blob, length integer, highestpriority integer). BUT, we have to do this incrementally so that we can handle blobs larger than available memory.