From dd9f5fb713db2471f6ab5cdfeda57fa10dae076b Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Mon, 7 Apr 2014 11:10:20 +0930 Subject: [PATCH] Only report that a payload exists if it actually exists --- rhizome_store.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/rhizome_store.c b/rhizome_store.c index d0fbfcc5..c7b8301b 100644 --- a/rhizome_store.c +++ b/rhizome_store.c @@ -32,7 +32,26 @@ int rhizome_exists(const rhizome_filehash_t *hashp) uint64_t gotfile = 0; if (sqlite_exec_uint64(&gotfile, "SELECT COUNT(*) FROM FILES WHERE id = ? and datavalid = 1;", RHIZOME_FILEHASH_T, hashp, END) != 1) return 0; - return gotfile; + if (gotfile==0) + return 0; + uint64_t blob_rowid; + if (sqlite_exec_uint64(&blob_rowid, + "SELECT rowid " + "FROM FILEBLOBS " + "WHERE id = ?", RHIZOME_FILEHASH_T, hashp, END) == -1) + return 0; + if (blob_rowid !=0) + return 1; + + // No row in FILEBLOBS, look for an external blob file. + char blob_path[1024]; + if (!FORMF_RHIZOME_STORE_PATH(blob_path, "%s/%s", RHIZOME_BLOB_SUBDIR, alloca_tohex_rhizome_filehash_t(*hashp))) + return 0; + + struct stat st; + if (stat(blob_path, &st) == -1) + return 0; + return 1; } /* Creates a row in the FILEBLOBS table and return the ROWID. Returns 0 if unsuccessful (error