]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/V2Writable.pm
v2writable: git_hash_raw: avoid $TMPDIR write
[public-inbox.git] / lib / PublicInbox / V2Writable.pm
index b51c85250a9b6be8794c30ea51879f1a2f5ffca1..0582dd5e32e8e87484c64d01447253af221e4a0c 100644 (file)
@@ -482,14 +482,12 @@ sub purge {
 sub git_hash_raw ($$) {
        my ($self, $raw) = @_;
        # grab the expected OID we have to reindex:
-       open my $tmp_fh, '+>', undef or die "failed to open tmp: $!";
-       $tmp_fh->autoflush(1);
-       print $tmp_fh $$raw or die "print \$tmp_fh: $!";
-       sysseek($tmp_fh, 0, 0) or die "seek failed: $!";
-
+       pipe(my($in, $w)) or die "pipe: $!";
        my $git_dir = $self->{-inbox}->git->{git_dir};
        my $cmd = ['git', "--git-dir=$git_dir", qw(hash-object --stdin)];
-       my $r = popen_rd($cmd, undef, { 0 => $tmp_fh });
+       my $r = popen_rd($cmd, undef, { 0 => $in });
+       print $w $$raw or die "print \$w: $!";
+       close $w or die "close \$w: $!";
        local $/ = "\n";
        chomp(my $oid = <$r>);
        close $r or die "git hash-object failed: $?";
@@ -1185,8 +1183,11 @@ sub sync_prepare ($$$) {
 
 sub unindex_oid_remote ($$$) {
        my ($self, $oid, $mid) = @_;
-       $_->remote_remove($oid, $mid) foreach @{$self->{idx_shards}};
-       $self->{over}->remove_oid($oid, $mid);
+       my @removed = $self->{over}->remove_oid($oid, $mid);
+       for my $num (@removed) {
+               my $idx = idx_shard($self, $num % $self->{shards});
+               $idx->remote_remove($oid, $num);
+       }
 }
 
 sub unindex_oid ($$$;$) {