From: Eric Wong Date: Fri, 17 Jul 2020 07:25:07 +0000 (+0000) Subject: v2writable: git_hash_raw: avoid $TMPDIR write X-Git-Tag: v1.6.0~226 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=340652d9833d9b7de4724a721e7014bfed262ccf;p=public-inbox.git v2writable: git_hash_raw: avoid $TMPDIR write We can rely on FD_CLOEXEC being set by default (since Perl 5.6+) on pipes to avoid FS/page-cache traffic, here. We also know "git hash-object" won't output anything until it's consumed all of its standard input; so there's no danger of a deadlock even in the the unlikely case git uses a hash that can't fit into PIPE_BUF :P --- diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index dffe90d8..0582dd5e 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -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: $?";