X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=aft.c;h=8473bc9b012b275518e056f2631222eaa954b462;hp=e1004d00c081eb77cdcdb04abc4554b13aa00715;hb=cdef208272294b567ec80b9defd60e57a0eb2587;hpb=0e8849e41ffaffdc94231568ff0a0a061500e341 diff --git a/aft.c b/aft.c index e1004d00..8473bc9b 100644 --- a/aft.c +++ b/aft.c @@ -126,8 +126,7 @@ static struct osl_column_description aft_cols[] = { } }; -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, @@ -704,7 +703,7 @@ static int print_list_item(struct ls_data *d, struct ls_options *opts, 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, @@ -745,7 +744,7 @@ static int print_list_item(struct ls_data *d, struct ls_options *opts, image_line, lyrics_line, afhi->bitrate, - "mp3", /* FIXME */ + audio_format_name(afsi->audio_format_id), afhi->frequency, afhi->channels, duration_buf, @@ -982,7 +981,7 @@ static int com_ls_callback(const struct osl_object *query, 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; @@ -1005,6 +1004,7 @@ static int com_ls_callback(const struct osl_object *query, 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); @@ -1124,8 +1124,8 @@ int com_afs_ls(int fd, int argc, char * const * const argv) 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; @@ -1244,6 +1244,8 @@ afhi <=> force or no HS #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) { @@ -1400,7 +1402,7 @@ static int add_one_audio_file(const char *arg, const void *private_data) 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]; @@ -1421,7 +1423,7 @@ static int add_one_audio_file(const char *arg, const void *private_data) 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. */ @@ -1444,7 +1446,8 @@ static int add_one_audio_file(const char *arg, const void *private_data) 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; } /* @@ -1453,11 +1456,8 @@ static int add_one_audio_file(const char *arg, const void *private_data) */ 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; } @@ -1470,11 +1470,14 @@ static int add_one_audio_file(const char *arg, const void *private_data) 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) @@ -1514,16 +1517,11 @@ 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; } @@ -1709,16 +1707,18 @@ void aft_shutdown(enum osl_close_flags flags) /** * 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) {