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.
-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(). */
}
/** The format of the data stored by save_audio_file_data(). */
objs[AFTCOL_PATH].size = strlen(path) + 1;
PARA_INFO_LOG("request to add %s\n", path);
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)
goto out;
if (hs && pb && hs == pb && !(flags & ADD_FLAG_FORCE)) {
if (flags & ADD_FLAG_VERBOSE)
{
char *path = aca->query.data;
struct osl_row *path_brother;
{
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));
return ret;
return pass_buffer_as_shm(aca->fd, SBD_OUTPUT, (char *)&path_brother,
sizeof(path_brother));
{
unsigned char *hash = aca->query.data;
struct osl_row *hash_sister;
{
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));
}
return pass_buffer_as_shm(aca->fd, SBD_OUTPUT, (char *)&hash_sister,
sizeof(hash_sister));
}