From: Andre Noll Date: Sun, 5 Apr 2015 13:12:18 +0000 (+0000) Subject: com_rm(): Return negative on errors X-Git-Tag: v0.5.6~94^2~23 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=b02b7155f01bbe802883e4085b93f146e06cc386 com_rm(): Return negative on errors --- diff --git a/aft.c b/aft.c index b79d7076..bfee23d9 100644 --- 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; } /**