The new option is quite easy to implement. The patch actually removes
more lines from aft.c than it adds, but this is just because the code
which loops over all matching files was duplicated across the two
branches of the clause which checks whether --reverse was given. The
branches can easily be combined.
{
const struct lls_command *cmd = SERVER_CMD_CMD_PTR(LS);
struct ls_options *opts = aca->query.data;
{
const struct lls_command *cmd = SERVER_CMD_CMD_PTR(LS);
struct ls_options *opts = aca->query.data;
time_t current_time;
const struct lls_opt_result *r_r;
time_t current_time;
const struct lls_opt_result *r_r;
ret = lls_deserialize_parse_result(
(char *)aca->query.data + sizeof(*opts), cmd, &opts->lpr);
ret = lls_deserialize_parse_result(
(char *)aca->query.data + sizeof(*opts), cmd, &opts->lpr);
prepare_ls_row));
if (ret < 0)
goto out;
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;
}
ret = lls_num_inputs(opts->lpr) > 0? -E_NO_MATCH : 0;
goto out;
}
if (ret < 0)
goto out;
time(¤t_time);
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);
out:
lls_free_parse_result(opts->lpr, cmd);
free(opts->data);
also given), chunk time and chunk offsets.
[/help]
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
[option basename]
short_opt = b
summary = list and match basenames only