lib/PublicInbox/V2Writable.pm | 23 ++++++++++++++--------- diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index eecc702b8a62f7148fb1ad42bfb0b261950e4def..aa812a6b3b3b4284329bcac6d447e8a5adbe6192 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -681,6 +681,18 @@ $self->git->cleanup; die $err if $err; } +sub write_alternates ($$$) { + my ($info_dir, $mode, $out) = @_; + my $fh = File::Temp->new(TEMPLATE => 'alt-XXXXXXXX', DIR => $info_dir); + my $tmp = $fh->filename; + print $fh @$out or die "print $tmp: $!\n"; + chmod($mode, $fh) or die "fchmod $tmp: $!\n"; + close $fh or die "close $tmp $!\n"; + my $alt = "$info_dir/alternates"; + rename($tmp, $alt) or die "rename $tmp => $alt: $!\n"; + $fh->unlink_on_destroy(0); +} + sub fill_alternates ($$) { my ($self, $epoch) = @_; @@ -719,15 +731,8 @@ $new = 1; } } return unless $new; - - my $fh = File::Temp->new(TEMPLATE => 'alt-XXXXXXXX', DIR => $info_dir); - my $tmp = $fh->filename; - print $fh join("\n", sort { $alt{$b} <=> $alt{$a} } keys %alt), "\n" - or die "print $tmp: $!\n"; - chmod($mode, $fh) or die "fchmod $tmp: $!\n"; - close $fh or die "close $tmp $!\n"; - rename($tmp, $alt) or die "rename $tmp => $alt: $!\n"; - $fh->unlink_on_destroy(0); + write_alternates($info_dir, $mode, + [join("\n", sort { $alt{$b} <=> $alt{$a} } keys %alt), "\n"]); } sub git_init {