From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7509720191 for ; Mon, 28 Nov 2022 05:32:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1669613561; bh=bv1+OFI1Zyis3587AYyiw9wTd35SvJ/qp9tlTGUgKZw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=5UjuUW+XGdt51b5mD3dp6nxh1HSKkOYlhjHCmbb4erascCuax7X90Y3Qb0grQJypt y9nYecwtkAlIWYnT5TCzElaeNUpPkr16bv/0WTHVAJcc0RQ/9IuFi4ZqxAVeGTwrgR uVekKZpgjYSb8OWVi4TtJflM/0j0y0XtffN3SIds= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 42/95] lei_mirror: hoist out dump_manifest sub Date: Mon, 28 Nov 2022 05:31:39 +0000 Message-Id: <20221128053232.291618-43-e@80x24.org> In-Reply-To: <20221128053232.291618-1-e@80x24.org> References: <20221128053232.291618-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We can reuse it in PublicInbox::Fetch, too. --- lib/PublicInbox/Fetch.pm | 10 +--------- lib/PublicInbox/LeiMirror.pm | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/lib/PublicInbox/Fetch.pm b/lib/PublicInbox/Fetch.pm index 3b6aa389..06ed775f 100644 --- a/lib/PublicInbox/Fetch.pm +++ b/lib/PublicInbox/Fetch.pm @@ -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; diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm index b0e6fa53..0df37724 100644 --- a/lib/PublicInbox/LeiMirror.pm +++ b/lib/PublicInbox/LeiMirror.pm @@ -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 }