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-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 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 BFD0D1F5AE; Fri, 17 Jul 2020 07:25:07 +0000 (UTC) Date: Fri, 17 Jul 2020 07:25:07 +0000 From: Eric Wong To: meta@public-inbox.org Subject: [9/8 PATCH] v2writable: git_hash_raw: avoid $TMPDIR write Message-ID: <20200717072507.GA22251@dcvr> References: <20200717063155.3734-1-e@yhbt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200717063155.3734-1-e@yhbt.net> List-Id: 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 --- lib/PublicInbox/V2Writable.pm | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index dffe90d8c..0582dd5e3 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: $?";