aft: Reorganize make_status_items().
[paraslash.git] / aft.c
diff --git a/aft.c b/aft.c
index 6c7f66643f1077083ab8317365aed9b622d12907..3283dda82d309769fa569d7ab6b32b299d368b4f 100644 (file)
--- 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(&current_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);