about summary refs log tree commit homepage
path: root/lib/PublicInbox/Msgmap.pm
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-21 08:29:25 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-22 00:12:43 +0000
commit2e5d47e4c02757c027461149b3e1568d713252b1 (patch)
tree3716730e94f8f9e5287650458d2c2146da2be140 /lib/PublicInbox/Msgmap.pm
parent8e52e5fdea416d6fda0b8d301144af0c043a5a76 (diff)
downloadpublic-inbox-2e5d47e4c02757c027461149b3e1568d713252b1.tar.gz
This will be used to keep track of Message-ID <-> NNTP Article
numbers to prevent article number reuse when reindexing.
Diffstat (limited to 'lib/PublicInbox/Msgmap.pm')
-rw-r--r--lib/PublicInbox/Msgmap.pm19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm
index 8e81fba0..78922d36 100644
--- a/lib/PublicInbox/Msgmap.pm
+++ b/lib/PublicInbox/Msgmap.pm
@@ -12,6 +12,7 @@ use strict;
 use warnings;
 use DBI;
 use DBD::SQLite;
+use File::Temp qw(tempfile);
 
 sub new {
         my ($class, $git_dir, $writable) = @_;
@@ -45,6 +46,18 @@ sub new_file {
         $self;
 }
 
+# used to keep track of used numeric mappings for v2 reindex
+sub tmp_clone {
+        my ($self) = @_;
+        my ($fh, $fn) = tempfile(EXLOCK => 0);
+        $self->{dbh}->sqlite_backup_to_file($fn);
+        my $tmp = ref($self)->new_file($fn, 1);
+        $tmp->{dbh}->do('PRAGMA synchronous = OFF');
+        $tmp->{tmp_name} = $fn; # SQLite won't work if unlinked, apparently
+        $fh = undef;
+        $tmp;
+}
+
 # n.b. invoked directly by scripts/xhdr-num2mid
 sub meta_accessor {
         my ($self, $key, $value) = @_;
@@ -189,4 +202,10 @@ sub mid_set {
         $sth->execute($num, $mid);
 }
 
+sub DESTROY {
+        my ($self) = @_;
+        delete $self->{dbh};
+        unlink $self->{tmp_name} if defined $self->{tmp_name};
+}
+
 1;