]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
convert: --wal affects altid SQLite DB, too
authorEric Wong <e@80x24.org>
Mon, 16 Mar 2026 02:41:29 +0000 (02:41 +0000)
committerEric Wong <e@80x24.org>
Wed, 18 Mar 2026 06:58:50 +0000 (06:58 +0000)
When converting v1 inboxes to v2, allow --wal, --no-fsync, and
future SQLite-specific switches to affect user-configured altid
SQLite DBs in addition to the prerequisite msgmap.sqlite3 and
over.sqlite3 DBs.

It's probably less surprising this way to have SQLite-related
switches affect all SQLite DB files, including user-maintained
ones.

lib/PublicInbox/AltId.pm
script/public-inbox-convert
t/www_altid.t

index 84d4d4e9da4a4496edab08bdf5919162de95dcca..47611c14e6ff8a8830797e3eba9a063e545949c9 100644 (file)
@@ -38,12 +38,11 @@ sub new {
        $self;
 }
 
-sub mm_alt ($) {
-       my ($self) = @_;
+sub mm_alt ($;$) {
+       my ($self, $opt) = @_;
        $self->{mm_alt} ||= eval {
                require PublicInbox::Msgmap;
-               # TODO: expose a way to disable fsync + enable WAL
-               my $opt = $self->{writable} ? { fsync => 1 } : undef;
+               $opt //= { fsync => 1 } if $self->{writable};
                PublicInbox::Msgmap->new_file($self->{filename}, $opt);
        };
 }
index 32cdf91e8842dd9be148ba7ab88a9a661f9a4371..724e4c61fa2c46fcd85cc323a7c6855504b0a4fa 100755 (executable)
@@ -109,10 +109,11 @@ sub link_or_copy ($$) {
                require PublicInbox::AltId;
                foreach my $i (0..$#$alt) {
                        my $src = PublicInbox::AltId->new($old, $alt->[$i], 0);
-                       $src = $src->mm_alt or next;
+                       $src = $src->mm_alt($opt) or next;
                        $src = $src->{dbh}->sqlite_db_filename;
                        my $dst = PublicInbox::AltId->new($new, $alt->[$i], 1);
-                       $dst->mm_alt->{dbh}->sqlite_backup_from_file($src);
+                       $dst->mm_alt($opt)->{dbh}->
+                               sqlite_backup_from_file($src);
                }
        }
        my $desc = "$old->{inboxdir}/description";
index c06e34d953202a29babab603bac26eef7b5b3377..9f882029431f89aeb176cf2a25d4857332900b87 100644 (file)
@@ -5,11 +5,9 @@ use strict; use v5.10.1; use PublicInbox::TestCommon;
 use PublicInbox::Config;
 use PublicInbox::Spawn qw(spawn);
 require_cmd('sqlite3');
-require_mods qw(DBD::SQLite psgi Xapian);
-use_ok($_) for qw(Plack::Test HTTP::Request::Common);
+require_mods qw(DBD::SQLite Xapian);
 require_ok 'PublicInbox::Msgmap';
 require_ok 'PublicInbox::AltId';
-require_ok 'PublicInbox::WWW';
 require IO::Uncompress::Gunzip;
 my ($tmpdir, $for_destroy) = tmpdir();
 my $aid = 'xyz';
@@ -39,7 +37,6 @@ EOF
 };
 $cfgpath //= "$ibx->{inboxdir}/cfg";
 my $cfg = PublicInbox::Config->new($cfgpath);
-my $www = PublicInbox::WWW->new($cfg);
 my $cmpfile = "$tmpdir/cmp.sqlite3";
 my $client = sub {
        my ($cb) = @_;
@@ -66,9 +63,27 @@ my $client = sub {
        is $res->code, 200, 'altid help hit';
        like $res->content, qr/\b$aid:/, 'altid shown in help';
 };
-test_psgi(sub { $www->call(@_) }, $client);
+my $env = { PI_CONFIG => $cfgpath, TMPDIR => $tmpdir };
 SKIP: {
-       my $env = { PI_CONFIG => $cfgpath, TMPDIR => $tmpdir };
+       require_mods 'psgi', 1;
+       require_ok 'PublicInbox::WWW';
+       my $www = PublicInbox::WWW->new($cfg);
+       test_psgi(sub { $www->call(@_) }, $client);
        test_httpd($env, $client);
 }
+
+SKIP: {
+       require_git v2.6, 1;
+       my ($out, $err) = ('', '');
+       my $rdr = { 1 => \$out, 2 => \$err };
+       my $v2dir = "$tmpdir/v2";
+       run_script([qw(-convert --wal), $ibx->{inboxdir}, $v2dir],
+                       $env, $rdr) or xbail "-convert: $err";
+       my $altid_file = "$v2dir/blah.sqlite3";
+       ok -s $altid_file, 'altid msgmap copied';
+       my $alt_mm = PublicInbox::Msgmap->new_file($altid_file);
+       is $alt_mm->{dbh}->selectrow_array('PRAGMA journal_mode'),
+               'wal', '-convert --wal affects copied altid SQLite DB';
+}
+
 done_testing;