From 99708bef7ad12ccb9399186f6055004d11bcf3db Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 1 Jun 2015 09:36:28 +0200 Subject: [PATCH] aft: Unify handling of hash and path duplicates. These are symmetric but were not treated as such. Specifically: * We ignored fatal errors for finding hash sisters while path brothers were handled strictly. * For hash sisters, we had a helper which implicitly special cased the non-fatal E_OSL_RB_KEY_NOT_FOUND case while the same check was open-coded for path brothers. This adds the find_path_brother() helper which is analogous to find_hash_sister() and fixes up the latter function to perform strict error checking rather than relying on the implementation detail that osl_get_row() sets the result pointer to NULL if no entry was found. --- aft.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/aft.c b/aft.c index 47931656..bfa4ce1a 100644 --- a/aft.c +++ b/aft.c @@ -1477,13 +1477,22 @@ int audio_file_loop(void *private_data, osl_rbtree_loop_func *func) func)); } -static struct osl_row *find_hash_sister(unsigned char *hash) +static int find_hash_sister(unsigned char *hash, struct osl_row **result) { - const struct osl_object obj = {.data = hash, .size = HASH_SIZE}; - struct osl_row *row; + int ret = aft_get_row_of_hash(hash, result); - osl_get_row(audio_file_table, AFTCOL_HASH, &obj, &row); - return row; + if (ret == -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND)) + return 0; + return ret; +} + +static int find_path_brother(const char *path, struct osl_row **result) +{ + int ret = aft_get_row_of_path(path, result); + + if (ret == -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND)) + return 0; + return ret; } /** The format of the data stored by save_audio_file_data(). */ @@ -1630,9 +1639,11 @@ static int com_add_callback(struct afs_callback_arg *aca) objs[AFTCOL_PATH].size = strlen(path) + 1; PARA_INFO_LOG("request to add %s\n", path); - hs = find_hash_sister(hash); - ret = aft_get_row_of_path(path, &pb); - if (ret < 0 && ret != -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND)) + ret = find_hash_sister(hash, &hs); + if (ret < 0) + goto out; + ret = find_path_brother(path, &pb); + if (ret < 0) goto out; if (hs && pb && hs == pb && !(flags & ADD_FLAG_FORCE)) { if (flags & ADD_FLAG_VERBOSE) @@ -1746,8 +1757,8 @@ static int path_brother_callback(struct afs_callback_arg *aca) { char *path = aca->query.data; struct osl_row *path_brother; - int ret = aft_get_row_of_path(path, &path_brother); - if (ret < 0) + int ret = find_path_brother(path, &path_brother); + if (ret <= 0) return ret; return pass_buffer_as_shm(aca->fd, SBD_OUTPUT, (char *)&path_brother, sizeof(path_brother)); @@ -1757,10 +1768,10 @@ static int hash_sister_callback(struct afs_callback_arg *aca) { unsigned char *hash = aca->query.data; struct osl_row *hash_sister; + int ret = find_hash_sister(hash, &hash_sister); - hash_sister = find_hash_sister(hash); - if (!hash_sister) - return 0; + if (ret <= 0) + return ret; return pass_buffer_as_shm(aca->fd, SBD_OUTPUT, (char *)&hash_sister, sizeof(hash_sister)); } -- 2.39.5