From: Andre Noll Date: Sat, 28 Oct 2023 17:20:14 +0000 (+0200) Subject: Merge topic branch t/ls-L into master X-Git-Tag: v0.7.3~10 X-Git-Url: http://git.tuebingen.mpg.de/?a=commitdiff_plain;h=624910afb851cf78669be188214b0332d5d5ee12;hp=101dcb49997b393280c10ba5a1cfc11e8fe0a091;p=paraslash.git Merge topic branch t/ls-L into master A single patch which implements the new --limit option for the ls server command. The confict in aft.c was trivial to fix. * refs/heads/t/ls-L: server: Implement ls --limit. --- diff --git a/NEWS.md b/NEWS.md index aa515e5a..5430790b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -18,6 +18,8 @@ NEWS - The select server command is now quiet by default, The new --verbose option can be used to show information about the newly loaded mood or playlist. +- The ls server command gained the --limit option to force a limit + on the number of files listed. Downloads: [tarball](./releases/paraslash-git.tar.xz) diff --git a/aft.c b/aft.c index 4ea8641b..f1aca7fb 100644 --- a/aft.c +++ b/aft.c @@ -1402,9 +1402,10 @@ static int com_ls_callback(struct afs_callback_arg *aca) { const struct lls_command *cmd = SERVER_CMD_CMD_PTR(LS); struct ls_options *opts = aca->query.data; - int i = 0, ret; + int ret; time_t current_time; const struct lls_opt_result *r_r, *r_a; + uint32_t limit, k, n; ret = lls_deserialize_parse_result( (char *)aca->query.data + sizeof(*opts), cmd, &opts->lpr); @@ -1420,7 +1421,8 @@ static int com_ls_callback(struct afs_callback_arg *aca) prepare_ls_row)); if (ret < 0) goto out; - if (opts->num_matching_paths == 0) { + n = opts->num_matching_paths; + if (n == 0) { ret = lls_num_inputs(opts->lpr) > 0? -E_NO_MATCH : 0; goto out; } @@ -1428,20 +1430,14 @@ static int com_ls_callback(struct afs_callback_arg *aca) if (ret < 0) goto out; time(¤t_time); - if (lls_opt_given(r_r)) - for (i = opts->num_matching_paths - 1; i >= 0; i--) { - ret = print_list_item(opts->data_ptr[i], opts, - &aca->pbout, current_time); - if (ret < 0) - goto out; - } - else - for (i = 0; i < opts->num_matching_paths; i++) { - ret = print_list_item(opts->data_ptr[i], opts, - &aca->pbout, current_time); - if (ret < 0) - goto out; - } + limit = SERVER_CMD_UINT32_VAL(LS, LIMIT, opts->lpr); + for (k = 0; k < n && (limit == 0 || k < limit); k++) { + uint32_t idx = lls_opt_given(r_r)? n - 1 - k : k; + ret = print_list_item(opts->data_ptr[idx], opts, &aca->pbout, + current_time); + if (ret < 0) + goto out; + } out: lls_free_parse_result(opts->lpr, cmd); free(opts->data); diff --git a/m4/lls/server_cmd.suite.m4 b/m4/lls/server_cmd.suite.m4 index 5b5c59ad..02afaabb 100644 --- a/m4/lls/server_cmd.suite.m4 +++ b/m4/lls/server_cmd.suite.m4 @@ -222,6 +222,16 @@ m4_include(`com_ll.m4') also given), chunk time and chunk offsets. [/help] + [option limit] + short_opt = L + summary = list at most this many files + arg_type = uint32 + arg_info = required_arg + typestr = num + [help] + An argument of zero means "unlimited". This is also the default which + applies if the option is not given. + [/help] [option basename] short_opt = b summary = list and match basenames only