]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - attribute.c
com_mvatt(): Return negative on errors
[paraslash.git] / attribute.c
index 0c23addf3228fb753f5ded3b49dafb45f4d5823e..70e35ae58f572308cb1a4a32266e122007e5a05c 100644 (file)
@@ -149,8 +149,9 @@ static int print_attribute(struct osl_table *table, struct osl_row *row,
        return 1;
 }
 
-static void com_lsatt_callback(int fd, const struct osl_object *query)
+static int com_lsatt_callback(int fd, const struct osl_object *query)
 {
+       int ret;
        struct lsatt_action_data laad = {
                .flags = *(unsigned *) query->data,
                .pb = {
@@ -177,15 +178,21 @@ static void com_lsatt_callback(int fd, const struct osl_object *query)
                pmd.loop_col_num = ATTCOL_NAME;
        if (laad.flags & LSATT_FLAG_REVERSE)
                pmd.pm_flags |= PM_REVERSE_LOOP;
-       for_each_matching_row(&pmd);
+       ret = for_each_matching_row(&pmd);
+       if (ret < 0)
+               goto out;
+       if (pmd.num_matches == 0)
+               ret = -E_NO_MATCH;
+out:
        flush_and_free_pb(&laad.pb);
+       return ret;
 }
 
 int com_lsatt(struct command_context *cc)
 {
        unsigned flags = 0;
        struct osl_object options = {.data = &flags, .size = sizeof(flags)};
-       int ret, i;
+       int i;
 
        for (i = 1; i < cc->argc; i++) {
                const char *arg = cc->argv[i];
@@ -208,13 +215,8 @@ int com_lsatt(struct command_context *cc)
                        continue;
                }
        }
-       ret = send_option_arg_callback_request(&options, cc->argc - i, cc->argv + i,
+       return send_option_arg_callback_request(&options, cc->argc - i, cc->argv + i,
                com_lsatt_callback, afs_cb_result_handler, cc);
-       if (ret < 0)
-               send_strerror(cc, -ret);
-       else if (ret == 0 && cc->argc > 1)
-               ret = send_sb_va(&cc->scc, SBD_ERROR_LOG, "no matches\n");
-       return ret;
 }
 
 struct addatt_event_data {
@@ -223,7 +225,7 @@ struct addatt_event_data {
 };
 
 
-static void com_addatt_callback(int fd, const struct osl_object *query)
+static int com_addatt_callback(int fd, const struct osl_object *query)
 {
        char *p;
        int ret = 1;
@@ -285,6 +287,7 @@ out:
        if (ret < 0)
                para_printf(&pb, "%s: %s\n", p, para_strerror(-ret));
        flush_and_free_pb(&pb);
+       return 0;
 }
 
 int com_addatt(struct command_context *cc)
@@ -300,7 +303,7 @@ int com_addatt(struct command_context *cc)
        return ret;
 }
 
-static void com_mvatt_callback(int fd, const struct osl_object *query)
+static int com_mvatt_callback(int fd, const struct osl_object *query)
 {
        char *old = query->data;
        size_t size = strlen(old) + 1;
@@ -325,23 +328,19 @@ static void com_mvatt_callback(int fd, const struct osl_object *query)
        ret = osl(osl_update_object(attribute_table, row, ATTCOL_NAME, &obj));
 out:
        if (ret < 0)
-               para_printf(&pb, "%s\n", para_strerror(-ret));
+               para_printf(&pb, "cannot rename %s to %s\n", old, new);
        else
                afs_event(ATTRIBUTE_RENAME, &pb, NULL);
        flush_and_free_pb(&pb);
+       return ret;
 }
 
 int com_mvatt(struct command_context *cc)
 {
-       int ret;
-
        if (cc->argc != 3)
                return -E_ATTR_SYNTAX;
-       ret = send_standard_callback_request(cc->argc - 1, cc->argv + 1,
+       return send_standard_callback_request(cc->argc - 1, cc->argv + 1,
                com_mvatt_callback, afs_cb_result_handler, cc);
-       if (ret < 0)
-               send_strerror(cc, -ret);
-       return ret;
 }
 
 /** Data passed to the action handler of com_rmatt(). */
@@ -379,7 +378,7 @@ static int remove_attribute(struct osl_table *table, struct osl_row *row,
        return 1;
 }
 
-static void com_rmatt_callback(int fd, const struct osl_object *query)
+static int com_rmatt_callback(int fd, const struct osl_object *query)
 {
        struct remove_attribute_action_data raad = {
                .num_removed = 0,
@@ -407,6 +406,7 @@ static void com_rmatt_callback(int fd, const struct osl_object *query)
        else if (!raad.num_removed)
                para_printf(&raad.pb, "no match -- nothing removed\n");
        flush_and_free_pb(&raad.pb);
+       return 0;
 }
 
 int com_rmatt(struct command_context *cc)