com_rm(): Return negative on errors
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 5 Apr 2015 13:12:18 +0000 (13:12 +0000)
committerAndre Noll <maan@tuebingen.mpg.de>
Wed, 12 Aug 2015 21:23:47 +0000 (23:23 +0200)
aft.c

diff --git a/aft.c b/aft.c
index b79d707..bfee23d 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -2142,7 +2142,7 @@ static int remove_audio_file(__a_unused struct osl_table *table,
        afs_event(AUDIO_FILE_REMOVE, &crd->pb, row);
        ret = osl(osl_del_row(audio_file_table, row));
        if (ret < 0)
-               para_printf(&crd->pb, "%s: %s\n", name, para_strerror(-ret));
+               para_printf(&crd->pb, "cannot remove %s\n", name);
        return ret;
 }
 
@@ -2171,16 +2171,15 @@ static int com_rm_callback(int fd, const struct osl_object *query)
        if (crd.flags & RM_FLAG_FNM_PATHNAME)
                pmd.fnmatch_flags |= FNM_PATHNAME;
        ret = for_each_matching_row(&pmd);
-       if (ret < 0) {
-               para_printf(&crd.pb, "%s\n", para_strerror(-ret));
-               return 0;
-       }
-       if ((pmd.num_matches == 0) && !(crd.flags & RM_FLAG_FORCE))
-               para_printf(&crd.pb, "no matches -- nothing removed\n");
+       if (ret < 0)
+               goto out;
+       if (pmd.num_matches == 0)
+               ret = -E_NO_MATCH;
        else if (crd.flags & RM_FLAG_VERBOSE)
-               para_printf(&crd.pb, "removed %u files\n", pmd.num_matches);
+               para_printf(&crd.pb, "removed %u file(s)\n", pmd.num_matches);
+out:
        flush_and_free_pb(&crd.pb);
-       return 0;
+       return ret;
 }
 
 /* TODO options: -r (recursive) */
@@ -2188,7 +2187,7 @@ int com_rm(struct command_context *cc)
 {
        uint32_t flags = 0;
        struct osl_object query = {.data = &flags, .size = sizeof(flags)};
-       int i, ret;
+       int i;
 
        for (i = 1; i < cc->argc; i++) {
                const char *arg = cc->argv[i];
@@ -2214,11 +2213,8 @@ int com_rm(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_rm_callback, afs_cb_result_handler, cc);
-       if (ret < 0)
-               send_strerror(cc, -ret);
-       return ret;
 }
 
 /**