]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - aft.c
com_touch(): Return negative on errors
[paraslash.git] / aft.c
diff --git a/aft.c b/aft.c
index acb6c6bf879f838976652ca3c48cfbf3ff75f70c..b79d7076a2905d644926f92f1d2515a24098055c 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -1323,8 +1323,7 @@ static int com_ls_callback(int fd, const struct osl_object *query)
        if (ret < 0)
                goto out;
        if (opts->num_matching_paths == 0) {
-               if (opts->num_patterns > 0)
-                       para_printf(&b, "no matches\n");
+               ret = opts->num_patterns > 0? -E_NO_MATCH : 0;
                goto out;
        }
        ret = sort_matching_paths(opts);
@@ -1348,7 +1347,7 @@ out:
        free(opts->data);
        free(opts->data_ptr);
        free(opts->patterns);
-       return 0;
+       return ret;
 }
 
 /*
@@ -1356,7 +1355,7 @@ out:
  */
 int com_ls(struct command_context *cc)
 {
-       int i, ret;
+       int i;
        unsigned flags = 0;
        enum ls_sorting_method sort = LS_SORT_BY_PATH;
        enum ls_listing_mode mode = LS_MODE_SHORT;
@@ -1465,9 +1464,8 @@ int com_ls(struct command_context *cc)
        opts.sorting = sort;
        opts.mode = mode;
        opts.num_patterns = cc->argc - i;
-       ret = send_option_arg_callback_request(&query, opts.num_patterns,
+       return send_option_arg_callback_request(&query, opts.num_patterns,
                cc->argv + i, com_ls_callback, afs_cb_result_handler, cc);
-       return ret;
 }
 
 /**
@@ -1737,9 +1735,9 @@ static int com_add_callback(int fd, const struct osl_object *query)
        afs_event(AUDIO_FILE_ADD, &msg, aft_row);
 out:
        if (ret < 0)
-               para_printf(&msg, "%s\n", para_strerror(-ret));
+               para_printf(&msg, "could not add %s\n", path);
        flush_and_free_pb(&msg);
-       return 0;
+       return ret;
 }
 
 /** Used by com_add(). */
@@ -1777,7 +1775,9 @@ static int get_row_pointer_from_result(struct osl_object *result,
                __a_unused uint8_t band, void *private)
 {
        struct osl_row **row = private;
-       *row = *(struct osl_row **)(result->data);
+
+       if (band == SBD_OUTPUT)
+               *row = *(struct osl_row **)(result->data);
        return 1;
 }
 
@@ -1974,12 +1974,12 @@ static int touch_audio_file(__a_unused struct osl_table *table,
 
        ret = get_afsi_object_of_row(row, &obj);
        if (ret < 0) {
-               para_printf(&tad->pb, "%s: %s\n", name, para_strerror(-ret));
+               para_printf(&tad->pb, "cannot touch %s\n", name);
                return ret;
        }
        ret = load_afsi(&old_afsi, &obj);
        if (ret < 0) {
-               para_printf(&tad->pb, "%s: %s\n", name, para_strerror(-ret));
+               para_printf(&tad->pb, "cannot touch %s\n", name);
                return ret;
        }
        new_afsi = old_afsi;
@@ -2036,12 +2036,10 @@ static int com_touch_callback(int fd, const struct osl_object *query)
        if (tad.cto->flags & TOUCH_FLAG_FNM_PATHNAME)
                pmd.fnmatch_flags |= FNM_PATHNAME;
        ret = for_each_matching_row(&pmd);
-       if (ret < 0)
-               para_printf(&tad.pb, "%s\n", para_strerror(-ret));
-       else if (pmd.num_matches == 0)
-               para_printf(&tad.pb, "no matches\n");
+       if (ret >= 0 && pmd.num_matches == 0)
+               ret = -E_NO_MATCH;
        flush_and_free_pb(&tad.pb);
-       return 0;
+       return ret;
 }
 
 int com_touch(struct command_context *cc)
@@ -2111,11 +2109,8 @@ int com_touch(struct command_context *cc)
        }
        if (i >= cc->argc)
                return -E_AFT_SYNTAX;
-       ret = send_option_arg_callback_request(&query, cc->argc - i,
+       return send_option_arg_callback_request(&query, cc->argc - i,
                cc->argv + i, com_touch_callback, afs_cb_result_handler, cc);
-       if (ret < 0)
-               send_strerror(cc, -ret);
-       return ret;
 }
 
 /** Flags for com_rm(). */