From 3b5c0d2092a1e3c282cba85edc2c1f3e20e3c916 Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Wed, 18 Dec 2013 17:40:24 +1030 Subject: [PATCH] More Rhizome external blob debug --- rhizome_database.c | 9 ++++++++- rhizome_store.c | 11 ++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/rhizome_database.c b/rhizome_database.c index 4249aea9..011be4be 100644 --- a/rhizome_database.c +++ b/rhizome_database.c @@ -1105,7 +1105,14 @@ static int rhizome_delete_external(const rhizome_filehash_t *hashp) char blob_path[1024]; if (!FORM_RHIZOME_DATASTORE_PATH(blob_path, alloca_tohex_rhizome_filehash_t(*hashp))) return -1; - return unlink(blob_path); + if (unlink(blob_path) == -1) { + if (errno != ENOENT) + return WHYF_perror("unlink(%s)", alloca_str_toprint(blob_path)); + return 1; + } + if (config.debug.externalblobs) + DEBUGF("Deleted blob file %s", blob_path); + return 0; } static int rhizome_delete_orphan_fileblobs_retry(sqlite_retry_state *retry) diff --git a/rhizome_store.c b/rhizome_store.c index 0fe4231b..2f2ddbaf 100644 --- a/rhizome_store.c +++ b/rhizome_store.c @@ -544,10 +544,12 @@ int rhizome_finish_write(struct rhizome_write *write) goto dbfailure; } - if (rename(blob_path, dest_path)){ + if (rename(blob_path, dest_path) == -1) { WHYF_perror("rename(%s, %s)", blob_path, dest_path); goto dbfailure; } + if (config.debug.externalblobs) + DEBUGF("Renamed %s to %s", blob_path, dest_path); }else{ if (sqlite_exec_void_retry( @@ -731,8 +733,11 @@ int rhizome_open_read(struct rhizome_read *read, const rhizome_filehash_t *hashp return -1; read->blob_fd = open(blob_path, O_RDONLY); if (read->blob_fd == -1) { - if (errno == ENOENT) + if (errno == ENOENT) { + if (config.debug.externalblobs) + DEBUGF("Stored file does not exist: %s", blob_path); return 1; // file not available + } return WHYF_perror("open(%s)", alloca_str_toprint(blob_path)); } off64_t pos = lseek64(read->blob_fd, 0, SEEK_END); @@ -740,7 +745,7 @@ int rhizome_open_read(struct rhizome_read *read, const rhizome_filehash_t *hashp return WHYF_perror("lseek64(%s,0,SEEK_END)", alloca_str_toprint(blob_path)); read->length = pos; if (config.debug.externalblobs) - DEBUGF("Opened stored file %s as fd %d, len %"PRIx64,blob_path, read->blob_fd, read->length); + DEBUGF("Opened stored file %s as fd %d, len %"PRIx64, blob_path, read->blob_fd, read->length); } read->offset = 0; read->hash_offset = 0;