]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_mirror: hoist out dump_manifest sub
authorEric Wong <e@80x24.org>
Mon, 28 Nov 2022 05:31:39 +0000 (05:31 +0000)
committerEric Wong <e@80x24.org>
Mon, 28 Nov 2022 23:38:56 +0000 (23:38 +0000)
We can reuse it in PublicInbox::Fetch, too.

lib/PublicInbox/Fetch.pm
lib/PublicInbox/LeiMirror.pm

index 3b6aa389f383405981a17c047d8a9bcaddddfedf..06ed775f6b274a716dc3b4cce4f3b9fadd56cc9a 100644 (file)
@@ -12,8 +12,6 @@ use PublicInbox::LEI;
 use PublicInbox::LeiCurl;
 use PublicInbox::LeiMirror;
 use File::Temp ();
-use PublicInbox::Config;
-use IO::Compress::Gzip qw(gzip $GzipError);
 
 sub new { bless {}, __PACKAGE__ }
 
@@ -233,13 +231,7 @@ EOM
        }
        for my $i (@new_epoch) { $mg->epoch_cfg_set($i) }
        if ($ft) {
-               if ($mculled) {
-                       my $json = PublicInbox::Config->json->encode($m1);
-                       my $fn = $ft->filename;
-                       my $mtime = (stat($fn))[9];
-                       gzip(\$json => $fn) or die "gzip: $GzipError";
-                       utime($mtime, $mtime, $fn) or die "utime(..., $fn): $!";
-               }
+               PublicInbox::LeiMirror::dump_manifest($m1 => $ft) if $mculled;
                PublicInbox::LeiMirror::ft_rename($ft, $mf, 0666);
        }
        $lei->child_error($xit << 8) if $fp2 && $xit;
index b0e6fa53c3bcb45aae8229be9dd7e6e1e5f4c94c..0df377244ba9afab728dfe4f1100ed7b17f02dfc 100644 (file)
@@ -595,6 +595,20 @@ EOM
        reap_live() while keys(%$LIVE);
 }
 
+sub dump_manifest ($$) {
+       my ($m, $ft) = @_;
+       # write the smaller manifest if epochs were skipped so
+       # users won't have to delete manifest if they +w an
+       # epoch they no longer want to skip
+       my $json = PublicInbox::Config->json->encode($m);
+       my $mtime = (stat($ft))[9];
+       seek($ft, SEEK_SET, 0) or die "seek($ft): $!";
+       truncate($ft, 0) or die "truncate($ft): $!";
+       gzip(\$json => $ft) or die "gzip($ft): $GzipError";
+       $ft->flush or die "flush($ft): $!";
+       utime($mtime, $mtime, "$ft") or die "utime(..., $ft): $!";
+}
+
 # FIXME: this gets confused by single inbox instance w/ global manifest.js.gz
 sub try_manifest {
        my ($self) = @_;
@@ -675,18 +689,7 @@ EOM
        return if $self->{lei}->{child_error} || $self->{dry_run};
 
        # set by clone_v2_prep/-I/--exclude
-       if (delete $self->{-culled_manifest}) {
-               # write the smaller manifest if epochs were skipped so
-               # users won't have to delete manifest if they +w an
-               # epoch they no longer want to skip
-               my $json = PublicInbox::Config->json->encode($m);
-               my $mtime = (stat($ft))[9];
-               seek($ft, SEEK_SET, 0) or die "seek($ft): $!";
-               truncate($ft, 0) or die "truncate($ft): $!";
-               gzip(\$json => $ft) or die "gzip($ft): $GzipError";
-               $ft->flush or die "flush($ft): $!";
-               utime($mtime, $mtime, "$ft") or die "utime(..., $ft): $!";
-       }
+       dump_manifest($m => $ft) if delete $self->{-culled_manifest};
        ft_rename($ft, "$self->{dst}/manifest.js.gz", 0666);
        open my $x, '>', "$self->{dst}/mirror.done"; # for _wq_done_wait
 }