From 711b364a5a88932de99aa559ce4a683b26dc2afc Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 26 May 2009 22:20:50 +0200 Subject: [PATCH] aft: Reorganize make_status_items(). It's cleaner to allocate the struct ls_data within make_status_items(). --- aft.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/aft.c b/aft.c index 6c7f6664..3283dda8 100644 --- a/aft.c +++ b/aft.c @@ -980,16 +980,35 @@ void make_empty_status_items(char *buf) ); } -static int make_status_items(struct ls_data *d, struct para_buffer *pb) -{ +static int make_status_items(struct audio_file_data *afd, + struct afs_info *afsi, char *path, long score, + HASH_TYPE *hash) +{ + struct ls_data d = { + .afhi = afd->afhi, /* struct copy */ + .afsi = *afsi, + .path = path, + .score = score, + .hash = hash + }; struct ls_options opts = { .flags = LS_FLAG_FULL_PATH | LS_FLAG_ADMISSIBLE_ONLY, .mode = LS_MODE_VERBOSE, }; + struct para_buffer pb = {.max_size = VERBOSE_LS_OUTPUT_SIZE - 1}; time_t current_time; + int ret; time(¤t_time); - return print_list_item(d, &opts, pb, current_time); + ret = print_list_item(&d, &opts, &pb, current_time); /* frees info string */ + afd->afhi.info_string = NULL; + if (ret < 0) + goto out; + strncpy(afd->verbose_ls_output, pb.buf, VERBOSE_LS_OUTPUT_SIZE); + afd->verbose_ls_output[VERBOSE_LS_OUTPUT_SIZE - 1] = '\0'; +out: + free(pb.buf); + return ret; } /** @@ -1052,23 +1071,9 @@ int open_and_update_audio_file(struct osl_row *aft_row, long score, save_afsi(&new_afsi, &afsi_obj); /* in-place update */ load_chunk_table(&afd->afhi, chunk_table_obj.data); - { - struct ls_data d = { - .afhi = afd->afhi, /* struct copy */ - .afsi = old_afsi, - .path = path, - .score = score, - .hash = file_hash - }; - struct para_buffer pb = {.max_size = VERBOSE_LS_OUTPUT_SIZE - 1}; - ret = make_status_items(&d, &pb); /* frees info string */ - afd->afhi.info_string = NULL; - if (ret < 0) - goto err; - strncpy(afd->verbose_ls_output, pb.buf, VERBOSE_LS_OUTPUT_SIZE); - afd->verbose_ls_output[VERBOSE_LS_OUTPUT_SIZE - 1] = '\0'; - free(pb.buf); - } + ret = make_status_items(afd, &old_afsi, path, score, file_hash); + if (ret < 0) + goto err; aced.aft_row = aft_row; aced.old_afsi = &old_afsi; afs_event(AFSI_CHANGE, NULL, &aced); -- 2.39.5