]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge topic branch t/ls-L into master
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 28 Oct 2023 17:20:14 +0000 (19:20 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 28 Oct 2023 19:50:40 +0000 (21:50 +0200)
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.

NEWS.md
aft.c
m4/lls/server_cmd.suite.m4

diff --git a/NEWS.md b/NEWS.md
index aa515e5af091eb23f266549a0cd33e974f993972..5430790bcc151fa90c93eabe66c009a1592c994f 100644 (file)
--- 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 4ea8641b2acce666e53d7005bd755ae2099cb07a..f1aca7fb8ccc3e31575303a4762d6a7ea35a054f 100644 (file)
--- 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(&current_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);
index 5b5c59ad58ad4ca07edefa3bd01311155ca1e5d5..02afaabb5252a0580711547ad399cef932cfcadc 100644 (file)
@@ -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