}
};
-static const struct osl_table_description audio_file_table_desc = {
- .dir = DATABASE_DIR,
+static struct osl_table_description audio_file_table_desc = {
.name = "audio_files",
.num_columns = NUM_AFT_COLUMNS,
.flags = OSL_LARGE_TABLE,
w->image_id_width, afsi->image_id,
w->lyrics_id_width, afsi->lyrics_id,
w->bitrate_width, afhi->bitrate,
- audio_format_name(afsi->audio_format_id), /* FIXME */
+ audio_format_name(afsi->audio_format_id),
w->frequency_width, afhi->frequency,
afhi->channels,
duration_buf,
image_line,
lyrics_line,
afhi->bitrate,
- "mp3", /* FIXME */
+ audio_format_name(afsi->audio_format_id),
afhi->frequency,
afhi->channels,
duration_buf,
prepare_ls_row);
if (ret < 0)
goto out;
- ret = opts->num_patterns? -E_NO_MATCH : 1;
+ ret = opts->num_patterns? -E_NO_MATCH : 0;
if (!opts->num_matching_paths) {
PARA_NOTICE_LOG("no match, ret: %d\n", ret);
goto out;
ret = 1;
out:
ls_output->data = b.buf;
+ PARA_NOTICE_LOG("ls_outoute.data: %p\n", ls_output->data);
ls_output->size = b.size;
free(opts->data);
free(opts->data_ptr);
opts.num_patterns = argc - i;
ret = send_option_arg_callback_request(&query, opts.num_patterns,
argv + i, com_ls_callback, &ls_output);
- if (ret >= 0 && ls_output.data) {
- send_buffer(fd, (char *)ls_output.data);
+ if (ret > 0) {
+ ret = send_buffer(fd, (char *)ls_output.data);
free(ls_output.data);
}
return ret;
#define ADD_FLAG_FORCE 2
#define ADD_FLAG_VERBOSE 4
+/* TODO: change log messages so that they get written to the result buffer */
+
static int com_add_callback(const struct osl_object *query,
__a_unused struct osl_object *result)
{
const struct private_add_data *pad = private_data;
struct audio_format_info afhi, *afhi_ptr = NULL;
struct osl_row *pb = NULL, *hs = NULL; /* path brother/hash sister */
- struct osl_object map, obj, query, result;
+ struct osl_object map, obj = {.data = NULL}, query, result;
char *path;
HASH_TYPE hash[HASH_SIZE];
ret = 1;
if (pb && (pad->flags & ADD_FLAG_LAZY)) { /* lazy is really cheap */
if (pad->flags & ADD_FLAG_VERBOSE)
- PARA_NOTICE_LOG("lazy-ignore: %s\n", path);
+ ret = send_va_buffer(pad->fd, "lazy-ignore: %s\n", path);
goto out_free;
}
/* We still want to add this file. Compute its hash. */
ret = 1;
if (pb && hs && hs == pb && (!(pad->flags & ADD_FLAG_FORCE))) {
if (pad->flags & ADD_FLAG_VERBOSE)
- PARA_NOTICE_LOG("not forcing update: %s\n", path);
+ ret = send_va_buffer(pad->fd,
+ "not forcing update: %s\n", path);
goto out_unmap;
}
/*
*/
if (!hs || (pad->flags & ADD_FLAG_FORCE)) {
ret = compute_afhi(path, map.data, map.size, &afhi);
- if (ret < 0) {
- PARA_WARNING_LOG("audio format of %s not recognized, skipping\n", path);
- ret = 1;
+ if (ret < 0)
goto out_unmap;
- }
format_num = ret;
afhi_ptr = &afhi;
}
out_unmap:
munmap(map.data, map.size);
out_free:
+ if (ret < 0)
+ send_va_buffer(pad->fd, "failed to add %s (%s)\n", path,
+ PARA_STRERROR(-ret));
free(obj.data);
free(path);
if (afhi_ptr)
free(afhi_ptr->chunk_table);
- return ret;
+ return 1; /* it's not an error if not all files could be added */
}
int com_add(int fd, int argc, char * const * const argv)
if (S_ISDIR(statbuf.st_mode)) {
ret = for_each_file_in_dir(argv[i],
add_one_audio_file, &pad);
- if (ret < 0)
- return ret;
continue;
}
ret = add_one_audio_file(argv[i], &pad);
- if (ret < 0)
- goto out;
}
ret = 1;
-out:
return ret;
}
/**
* Open the audio file table.
*
- * \param ti Gets initialized by this function
+ * \param ti Gets initialized by this function.
+ * \param db The database directory.
*
* \return Positive on success, negative on errors.
*
* \sa osl_open_table().
*/
-int aft_init(struct table_info *ti)
+int aft_init(struct table_info *ti, const char *db)
{
int ret;
+ audio_file_table_desc.dir = db;
ti->desc = &audio_file_table_desc;
ret = osl_open_table(ti->desc, &ti->table);
if (ret >= 0) {