the paraslash-0.3.1 release tarball
[paraslash.git] / aft.c
diff --git a/aft.c b/aft.c
index 2b7a7af7efaa8d8fb72b55eb48616103c04cf1eb..0e3f83e85524b3fea16d64bb612f10a3e9189abd 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2007-2008 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -660,6 +660,7 @@ int open_and_update_audio_file(struct osl_row *aft_row, long score,
                AFTCOL_CHUNKS, &chunk_table_obj);
        if (ret < 0)
                return ret;
+       afd->afhi.chunk_table = NULL;
        ret = mmap_full_file(path, O_RDONLY, &map.data,
                &map.size, &afd->fd);
        if (ret < 0)
@@ -697,10 +698,8 @@ int open_and_update_audio_file(struct osl_row *aft_row, long score,
        aced.old_afsi = &old_afsi;
        afs_event(AFSI_CHANGE, NULL, &aced);
        ret = save_afd(afd);
-       free(afd->afhi.chunk_table);
-       if (ret < 0)
-               goto err;
 err:
+       free(afd->afhi.chunk_table);
        osl_close_disk_object(&chunk_table_obj);
        return ret;
 }
@@ -1870,6 +1869,8 @@ struct touch_action_data {
        struct com_touch_options *cto;
        /** Message buffer. */
        struct para_buffer pb;
+       /** How many audio files matched the given pattern. */
+       unsigned num_matches;
 };
 
 static int touch_audio_file(__a_unused struct osl_table *table,
@@ -1912,6 +1913,7 @@ static int touch_audio_file(__a_unused struct osl_table *table,
                if (tad->cto->last_played >= 0)
                        new_afsi.last_played = tad->cto->last_played;
        }
+       tad->num_matches++;
        save_afsi(&new_afsi, &obj); /* in-place update */
        aced.aft_row = row;
        aced.old_afsi = &old_afsi;
@@ -1938,6 +1940,9 @@ static int com_touch_callback(const struct osl_object *query,
        ret = for_each_matching_row(&pmd);
        if (ret < 0)
                para_printf(&tad.pb, "%s\n", para_strerror(-ret));
+       else
+               if (!tad.num_matches)
+                       para_printf(&tad.pb, "no matches\n");
        if (tad.pb.buf) {
                result->data = tad.pb.buf;
                result->size = tad.pb.size;
@@ -2005,11 +2010,14 @@ int com_touch(int fd, int argc, char * const * const argv)
                return -E_AFT_SYNTAX;
        ret = send_option_arg_callback_request(&query, argc - i,
                argv + i, com_touch_callback, &result);
-       if (ret > 0) {
-               send_buffer(fd, (char *)result.data);
-               free(result.data);
-       } else if (ret < 0)
+       if (!ret)
+               return 0;
+       if (ret < 0) {
                send_va_buffer(fd, "%s\n", para_strerror(-ret));
+               return ret;
+       }
+       ret = send_buffer(fd, (char *)result.data);
+       free(result.data);
        return ret;
 }
 
@@ -2117,11 +2125,14 @@ int com_rm(int fd, int argc,  char * const * const argv)
                return -E_AFT_SYNTAX;
        ret = send_option_arg_callback_request(&query, argc - i, argv + i,
                com_rm_callback, &result);
-       if (ret > 0) {
-               send_buffer(fd, (char *)result.data);
-               free(result.data);
-       } else if (ret < 0)
+       if (!ret)
+               return 0;
+       if (ret < 0) {
                send_va_buffer(fd, "%s\n", para_strerror(-ret));
+               return ret;
+       }
+       ret = send_buffer(fd, (char *)result.data);
+       free(result.data);
        return ret;
 }
 
@@ -2278,11 +2289,14 @@ int com_cpsi(int fd, int argc,  char * const * const argv)
                flags = ~(unsigned)CPSI_FLAG_VERBOSE | flags;
        ret = send_option_arg_callback_request(&options, argc - i, argv + i,
                com_cpsi_callback, &result);
-       if (ret > 0) {
-               send_buffer(fd, (char *)result.data);
-               free(result.data);
-       } else
+       if (!ret)
+               return 0;
+       if (ret < 0) {
                send_va_buffer(fd, "%s\n", para_strerror(-ret));
+               return ret;
+       }
+       ret = send_buffer(fd, (char *)result.data);
+       free(result.data);
        return ret;
 }