about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-04-27 11:07:49 +0000
committerEric Wong <e@80x24.org>2021-04-27 21:28:55 -0400
commitc7ec7eb31e5c770636275b850bcdc8b9ae0f59dd (patch)
tree7405d49b17ed3e2a02bbb394e4d85ff4ce74965d /lib
parentfb7702f0888e9bdad98f33c09c4048625322a688 (diff)
downloadpublic-inbox-c7ec7eb31e5c770636275b850bcdc8b9ae0f59dd.tar.gz
This will be useful, later.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/LEI.pm2
-rw-r--r--lib/PublicInbox/LeiExternal.pm2
-rw-r--r--lib/PublicInbox/LeiLsSync.pm29
3 files changed, 32 insertions, 1 deletions
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 39278de6..c170572b 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -161,6 +161,8 @@ our %CMD = ( # sorted in order of importance/use:
 'ls-external' => [ '[FILTER]', 'list publicinbox|extindex locations',
         qw(format|f=s z|0 globoff|g invert-match|v local remote), @c_opt ],
 'ls-label' => [ '', 'list labels', qw(z|0 stats:s), @c_opt ],
+'ls-sync' => [ '', 'list sync folders',
+                qw(z|0 z|0 globoff|g invert-match|v local remote), @c_opt ],
 'forget-external' => [ 'LOCATION...|--prune',
         'exclude further results from a publicinbox|extindex',
         qw(prune), @c_opt ],
diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm
index b0ebe947..3858085e 100644
--- a/lib/PublicInbox/LeiExternal.pm
+++ b/lib/PublicInbox/LeiExternal.pm
@@ -50,7 +50,7 @@ my %re_map = ( '*' => '[^/]*?', '?' => '[^/]',
                 '[' => '[', ']' => ']', ',' => ',' );
 
 sub glob2re {
-        my ($re) = @_;
+        my $re = $_[-1];
         my $p = '';
         my $in_bracket = 0;
         my $qm = 0;
diff --git a/lib/PublicInbox/LeiLsSync.pm b/lib/PublicInbox/LeiLsSync.pm
new file mode 100644
index 00000000..71f111a9
--- /dev/null
+++ b/lib/PublicInbox/LeiLsSync.pm
@@ -0,0 +1,29 @@
+# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# front-end for the "lei ls-sync" sub-command
+package PublicInbox::LeiLsSync;
+use strict;
+use v5.10.1;
+use PublicInbox::LeiMailSync;
+
+sub lei_ls_sync {
+        my ($lei, $filter) = @_;
+        my $sto = $lei->_lei_store or return;
+        my $lms = $sto->search->lms or return;
+        my $opt = $lei->{opt};
+        my $re;
+        $re = defined($filter) ? qr/\Q$filter\E/ : qr/./ if $opt->{globoff};
+        $re //= $lei->glob2re($filter // '*');
+        my @f = $lms->folders;
+        @f = $opt->{'invert-match'} ? grep(!/$re/, @f) : grep(/$re/, @f);
+        if ($opt->{'local'} && !$opt->{remote}) {
+                @f = grep(!m!\A[a-z\+]+://!i, @f);
+        } elsif ($opt->{remote} && !$opt->{'local'}) {
+                @f = grep(m!\A[a-z\+]+://!i, @f);
+        }
+        my $ORS = $opt->{z} ? "\0" : "\n";
+        $lei->out(join($ORS, @f, ''));
+}
+
+1;