]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LEI.pm
lei import: keep sync info for Maildir and IMAP folders
[public-inbox.git] / lib / PublicInbox / LEI.pm
index 8fa8994488e12ae82ca22503bbfad095ae4ca0eb..39278de640a0ab9004597d281ae3484caa18b140 100644 (file)
@@ -64,9 +64,13 @@ sub opt_dash ($$) {
        ($spec, '<>' => $cb, $GLP_PASS) # for Getopt::Long
 }
 
-sub rel2abs ($$) {
+# rel2abs preserves symlinks in parent, unlike abs_path
+sub rel2abs {
        my ($self, $p) = @_;
-       return $p if index($p, '/') == 0; # already absolute
+       if (index($p, '/') == 0) { # already absolute
+               $p =~ tr!/!/!s; # squeeze redundant slashes
+               return $p;
+       }
        my $pwd = $self->{env}->{PWD};
        my $cwd;
        if (defined $pwd) {
@@ -84,6 +88,9 @@ sub rel2abs ($$) {
        File::Spec->rel2abs($p, $pwd);
 }
 
+# abs_path resolves symlinks in parent iff all parents exist
+sub abs_path { Cwd::abs_path($_[1]) // rel2abs(@_) }
+
 sub share_path ($) { # $HOME/.local/share/lei/$FOO
        my ($self) = @_;
        rel2abs($self, ($self->{env}->{XDG_DATA_HOME} //
@@ -181,7 +188,7 @@ our %CMD = ( # sorted in order of importance/use:
        qw(exact! all jobs:i indexed), @c_opt ],
 
 'add-watch' => [ 'LOCATION', 'watch for new messages and flag changes',
-       qw(import! kw|keywords|flags! interval=s recursive|r
+       qw(import! kw! interval=s recursive|r
        exclude=s include=s), @c_opt ],
 'ls-watch' => [ '[FILTER...]', 'list active watches with numbers and status',
                qw(format|f=s z), @c_opt ],
@@ -193,11 +200,11 @@ our %CMD = ( # sorted in order of importance/use:
 'import' => [ 'LOCATION...|--stdin',
        'one-time import/update from URL or filesystem',
        qw(stdin| offset=i recursive|r exclude=s include|I=s
-       lock=s@ in-format|F=s kw|keywords|flags! verbose|v+), @c_opt ],
+       lock=s@ in-format|F=s kw! verbose|v+ incremental! sync!), @c_opt ],
 'convert' => [ 'LOCATION...|--stdin',
        'one-time conversion from URL or filesystem to another format',
        qw(stdin| in-format|F=s out-format|f=s output|mfolder|o=s
-       lock=s@ kw|keywords|flags!), @c_opt ],
+       lock=s@ kw!), @c_opt ],
 'p2q' => [ 'FILE|COMMIT_OID|--stdin',
        "use a patch to generate a query for `lei q --stdin'",
        qw(stdin| want|w=s@ uri debug), @c_opt ],
@@ -205,6 +212,9 @@ our %CMD = ( # sorted in order of importance/use:
                'git-config(1) wrapper for '._config_path($_[0]);
        }, qw(config-file|system|global|file|f=s), # for conflict detection
         qw(c=s@ C=s@), pass_through('git config') ],
+'inspect' => [ 'ITEMS...', 'inspect lei/store and/or local external',
+       qw(pretty ascii dir=s), @c_opt ],
+
 'init' => [ '[DIRNAME]', sub {
        "initialize storage, default: ".store_path($_[0]);
        }, @c_opt ],
@@ -244,6 +254,7 @@ my %OPTDESC = (
 'lock=s@' => [ 'METHOD|dotlock|fcntl|flock|none',
        'mbox(5) locking method(s) to use (default: fcntl,dotlock)' ],
 
+'incremental!  import' => 'import already seen IMAP and NNTP articles',
 'globoff|g' => "do not match locations using '*?' wildcards ".
                "and\xa0'[]'\x{a0}ranges",
 'verbose|v+' => 'be more verbose',
@@ -348,7 +359,7 @@ my %OPTDESC = (
 
 'by-mid|mid:s' => [ 'MID', 'match only by Message-ID, ignoring contents' ],
 
-'kw|keywords|flags!' => 'disable/enable importing flags',
+'kw!' => 'disable/enable importing keywords (aka "flags")',
 
 # xargs, env, use "-0", git(1) uses "-z".  We support z|0 everywhere
 'z|0' => 'use NUL \\0 instead of newline (CR) to delimit lines',
@@ -1211,4 +1222,11 @@ sub DESTROY {
        $? = $err if $err; # preserve ->fail or ->x_it code
 }
 
+sub wq_done_wait { # dwaitpid callback
+       my ($arg, $pid) = @_;
+       my ($wq, $lei, $e) = @$arg;
+       $? and $lei->child_error($?, $e ? "$e errors during $lei->{cmd}" : ());
+       $lei->dclose;
+}
+
 1;