Fix Rhizome cleanup to remove temporary payloads

Fix test case to properly assert that all stale payloads are
deleted
This commit is contained in:
Andrew Bettison 2014-03-18 16:03:26 +10:30
parent dc588e964d
commit 53d5a8734b
2 changed files with 7 additions and 12 deletions

View File

@ -1187,11 +1187,11 @@ int rhizome_database_filehash_from_id(const rhizome_bid_t *bidp, uint64_t versio
OUT(); OUT();
} }
static int rhizome_delete_external(const rhizome_filehash_t *hashp) static int rhizome_delete_external(const char *id)
{ {
// attempt to remove any external blob // attempt to remove any external blob
char blob_path[1024]; char blob_path[1024];
if (!FORM_RHIZOME_DATASTORE_PATH(blob_path, "%s/%s", RHIZOME_BLOB_SUBDIR, alloca_tohex_rhizome_filehash_t(*hashp))) if (!FORM_RHIZOME_DATASTORE_PATH(blob_path, "%s/%s", RHIZOME_BLOB_SUBDIR, id))
return -1; return -1;
if (unlink(blob_path) == -1) { if (unlink(blob_path) == -1) {
if (errno != ENOENT) if (errno != ENOENT)
@ -1252,11 +1252,8 @@ int rhizome_cleanup(struct rhizome_cleanup_report *report)
while (sqlite_step_retry(&retry, statement) == SQLITE_ROW) { while (sqlite_step_retry(&retry, statement) == SQLITE_ROW) {
candidates++; candidates++;
const char *id = (const char *) sqlite3_column_text(statement, 0); const char *id = (const char *) sqlite3_column_text(statement, 0);
rhizome_filehash_t hash; if (rhizome_delete_external(id) == 0 && report)
if (str_to_rhizome_filehash_t(&hash, id) == -1) ++report->deleted_stale_incoming_files;
WARNF("invalid field FILES.id=%s -- ignored", alloca_str_toprint(id));
else if (rhizome_delete_external(&hash) == 0 && report)
++report->deleted_stale_incoming_files;
} }
sqlite3_finalize(statement); sqlite3_finalize(statement);
@ -1267,10 +1264,7 @@ int rhizome_cleanup(struct rhizome_cleanup_report *report)
while (sqlite_step_retry(&retry, statement) == SQLITE_ROW) { while (sqlite_step_retry(&retry, statement) == SQLITE_ROW) {
candidates++; candidates++;
const char *id = (const char *) sqlite3_column_text(statement, 0); const char *id = (const char *) sqlite3_column_text(statement, 0);
rhizome_filehash_t hash; if (rhizome_delete_external(id) == 0 && report)
if (str_to_rhizome_filehash_t(&hash, id) == -1)
WARNF("invalid field FILES.id=%s -- ignored", alloca_str_toprint(id));
else if (rhizome_delete_external(&hash) == 0 && report)
++report->deleted_orphan_files; ++report->deleted_orphan_files;
} }
sqlite3_finalize(statement); sqlite3_finalize(statement);
@ -1981,7 +1975,7 @@ static int rhizome_delete_manifest_retry(sqlite_retry_state *retry, const rhizom
static int rhizome_delete_file_retry(sqlite_retry_state *retry, const rhizome_filehash_t *hashp) static int rhizome_delete_file_retry(sqlite_retry_state *retry, const rhizome_filehash_t *hashp)
{ {
int ret = 0; int ret = 0;
rhizome_delete_external(hashp); rhizome_delete_external(alloca_tohex_rhizome_filehash_t(*hashp));
sqlite3_stmt *statement = sqlite_prepare_bind(retry, "DELETE FROM files WHERE id = ?", RHIZOME_FILEHASH_T, hashp, END); sqlite3_stmt *statement = sqlite_prepare_bind(retry, "DELETE FROM files WHERE id = ?", RHIZOME_FILEHASH_T, hashp, END);
if (!statement || sqlite_exec_retry(retry, statement) == -1) if (!statement || sqlite_exec_retry(retry, statement) == -1)
ret = -1; ret = -1;

View File

@ -927,6 +927,7 @@ test_MeshMSAddGrow() {
for ofilehash in "${ofilehashes[@]}"; do for ofilehash in "${ofilehashes[@]}"; do
execute --exit-status=1 --stderr $servald rhizome export file "$ofilehash" execute --exit-status=1 --stderr $servald rhizome export file "$ofilehash"
done done
filehash="$filehashx"
done done
} }