aft: Update mtime and file size on afhi changes.
[paraslash.git] / aft.c
diff --git a/aft.c b/aft.c
index 0e86b12d6c13ea1992c0c751dae61df43f78b226..59be56eb68cd274debfe5077c5031687121fc7fa 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -1043,6 +1043,28 @@ out:
 static struct ls_data status_item_ls_data;
 static struct osl_row *current_aft_row;
 
+static void make_inode_status_items(struct para_buffer *pb)
+{
+       struct stat statbuf = {.st_size = 0};
+       char *path, mtime_str[30] = "\0";
+       struct tm mtime_tm;
+       int ret;
+
+       ret = get_audio_file_path_of_row(current_aft_row, &path);
+       if (ret < 0)
+               goto out;
+       ret = stat(path, &statbuf);
+       if (ret < 0)
+               goto out;
+       localtime_r(&statbuf.st_mtime, &mtime_tm);
+       ret = strftime(mtime_str, 29, "%b %d %Y", &mtime_tm);
+       assert(ret > 0); /* number of bytes placed in mtime_str */
+out:
+       /* We don't care too much about errors here */
+       (void)WRITE_STATUS_ITEM(pb, SI_MTIME, "%s\n", mtime_str);
+       (void)WRITE_STATUS_ITEM(pb, SI_FILE_SIZE, "%ld\n", statbuf.st_size / 1024);
+}
+
 static int make_status_items(void)
 {
        struct ls_options opts = {
@@ -1057,6 +1079,7 @@ static int make_status_items(void)
        ret = print_list_item(&status_item_ls_data, &opts, &pb, current_time);
        if (ret < 0)
                return ret;
+       make_inode_status_items(&pb);
        free(status_items);
        status_items = pb.buf;
        memset(&pb, 0, sizeof(pb));
@@ -1068,6 +1091,7 @@ static int make_status_items(void)
                status_items = NULL;
                return ret;
        }
+       make_inode_status_items(&pb);
        free(parser_friendly_status_items);
        parser_friendly_status_items = pb.buf;
        return 1;