]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei up: fix canonicalization of Maildirs
authorEric Wong <e@80x24.org>
Sat, 17 Apr 2021 10:24:45 +0000 (10:24 +0000)
committerEric Wong <e@80x24.org>
Sat, 17 Apr 2021 20:16:42 +0000 (20:16 +0000)
We always represent --output destination directories with a
trailing slash to disambiguate directories from mbox filenames.
Therefore, we must use the trailing slash when mapping the
destination beck from the lei/saved-search/* directory.

"lei up" now relies exclusively on the users --output pathname
or URL for updates.  This ought to be less confusing since
pathnames in ~/.local/store/lei/saved-searches aren't ideal.

lib/PublicInbox/LeiSavedSearch.pm
t/lei-q-save.t

index 932b2aa4c728d0b758526289b6c7f90f21ff19a8..0f632d9378aacfb2b8625b66185fce131d6d44d4 100644 (file)
@@ -26,18 +26,21 @@ sub lss_dir_for ($$) {
        } else { # basename
                @n = ($$dstref =~ m{([\w\-\.]+)/*\z});
                $$dstref = $lei->rel2abs($$dstref);
+               $$dstref .= '/' if -d $$dstref;
        }
        push @n, sha256_hex($$dstref);
        $lei->share_path . '/saved-searches/' . join('-', @n);
 }
 
 sub new {
-       my ($cls, $lei, $dir) = @_;
+       my ($cls, $lei, $dst) = @_;
        my $self = bless { ale => $lei->ale }, $cls;
-       if (defined $dir) { # updating existing saved search via "lei up"
-               my $f = "$dir/lei.saved-search";
-               ((-f $f && -r _) || output2lssdir($self, $lei, \$dir, \$f)) or
-                       return $lei->fail("$f non-existent or unreadable");
+       my $dir;
+       if (defined $dst) { # updating existing saved search via "lei up"
+               my $f;
+               $dir = $dst;
+               output2lssdir($self, $lei, \$dir, \$f) or
+                       return $lei->fail("--save was not used with $dst");
                $self->{-cfg} //= PublicInbox::Config::git_config_dump($f);
                $self->{'-f'} = $f;
        } else { # new saved search "lei q --save"
index d43f508b550c045e09e038ad35ea76ea2ea4e2fe..6389825f46d260e353769d0c266739638bf6bb22 100644 (file)
@@ -27,7 +27,9 @@ test_lei(sub {
        # ensure "lei up" works, since it compliments "lei q --save"
        $in = $doc2->as_string;
        lei_ok [qw(import -q -F eml -)], undef, { 0 => \$in, %$lei_opt };
-       lei_ok qw(up -q), $s[0];
+       opendir my $dh, '.' or xbail "opendir .: $!";
+       lei_ok qw(up -q md -C), $home;
+       chdir($dh) or xbail "fchdir . $!";
        my %after = map { $_ => 1 } glob("$home/md/cur/*");
        is(delete $after{(keys(%before))[0]}, 1, 'original message kept');
        is(scalar(keys %after), 1, 'one new message added');