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 3EBF71FC99 for ; Sun, 28 Mar 2021 09:01:26 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 12/12] treewide: shorten temporary filename Date: Sun, 28 Mar 2021 09:01:24 +0000 Message-Id: <20210328090124.3541-13-e@80x24.org> In-Reply-To: <20210328090124.3541-1-e@80x24.org> References: <20210328090124.3541-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: File::Temp only requires four 'X' characters (unlike mkstemp(3), which requires six). So only so only give it 4 to avoid an 80-column violation and maybe save metadata space on FSes. --- lib/PublicInbox/LeiOverview.pm | 2 +- lib/PublicInbox/Msgmap.pm | 2 +- lib/PublicInbox/SolverGit.pm | 2 +- lib/PublicInbox/TestCommon.pm | 2 +- lib/PublicInbox/V2Writable.pm | 6 +++--- lib/PublicInbox/Xapcmd.pm | 9 ++++----- script/public-inbox-edit | 2 +- script/public-inbox-init | 2 +- scripts/ssoma-replay | 2 +- t/check-www-inbox.perl | 2 +- t/inbox.t | 2 +- t/nodatacow.t | 2 +- 12 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/PublicInbox/LeiOverview.pm b/lib/PublicInbox/LeiOverview.pm index 8e26cba4..68f6c792 100644 --- a/lib/PublicInbox/LeiOverview.pm +++ b/lib/PublicInbox/LeiOverview.pm @@ -26,7 +26,7 @@ sub _iso8601 ($) { strftime('%Y-%m-%dT%H:%M:%SZ', gmtime($_[0])) } # we open this in the parent process before ->wq_io_do handoff sub ovv_out_lk_init ($) { my ($self) = @_; - my $tmp = File::Temp->new("lei-ovv.dst.$$.lock-XXXXXX", + my $tmp = File::Temp->new("lei-ovv.dst.$$.lock-XXXX", TMPDIR => 1, UNLINK => 0); $self->{"lk_id.$self.$$"} = $self->{lock_path} = $tmp->filename; } diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm index 826c4b30..16a9a476 100644 --- a/lib/PublicInbox/Msgmap.pm +++ b/lib/PublicInbox/Msgmap.pm @@ -46,7 +46,7 @@ sub new_file { sub tmp_clone { my ($self, $dir) = @_; require File::Temp; - my $tmp = "mm_tmp-$$-XXXXXX"; + my $tmp = "mm_tmp-$$-XXXX"; my ($fh, $fn) = File::Temp::tempfile($tmp, EXLOCK => 0, DIR => $dir); PublicInbox::Spawn::nodatacow_fd(fileno($fh)); $self->{dbh}->sqlite_backup_to_file($fn); diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm index 1d70975e..92106e75 100644 --- a/lib/PublicInbox/SolverGit.pm +++ b/lib/PublicInbox/SolverGit.pm @@ -681,7 +681,7 @@ sub solve ($$$$$) { $self->{todo} = [ { %$hints, oid_b => $oid_want } ]; $self->{patches} = []; # [ $di, $di, ... ] $self->{found} = {}; # { abbr => [ ::Git, oid, type, size, $di ] } - $self->{tmp} = File::Temp->newdir("solver.$oid_want-XXXXXXXX", TMPDIR => 1); + $self->{tmp} = File::Temp->newdir("solver.$oid_want-XXXX", TMPDIR => 1); dbg($self, "solving $oid_want ..."); if (my $async = $env->{'pi-httpd.async'}) { diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index d36a63aa..d6e090dd 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -40,7 +40,7 @@ sub tmpdir (;$) { unless (defined $base) { ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!); } - my $tmpdir = File::Temp->newdir("pi-$base-$$-XXXXXX", TMPDIR => 1); + my $tmpdir = File::Temp->newdir("pi-$base-$$-XXXX", TMPDIR => 1); ($tmpdir->dirname, $tmpdir); } diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index 4130a472..0461257f 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -660,7 +660,7 @@ sub done { sub write_alternates ($$$) { my ($info_dir, $mode, $out) = @_; - my $fh = File::Temp->new(TEMPLATE => 'alt-XXXXXXXX', DIR => $info_dir); + my $fh = File::Temp->new(TEMPLATE => 'alt-XXXX', DIR => $info_dir); my $tmp = $fh->filename; print $fh @$out or die "print $tmp: $!\n"; chmod($mode, $fh) or die "fchmod $tmp: $!\n"; @@ -772,11 +772,11 @@ sub import_init { sub diff ($$$) { my ($mid, $cur, $new) = @_; - my $ah = File::Temp->new(TEMPLATE => 'email-cur-XXXXXXXX', TMPDIR => 1); + my $ah = File::Temp->new(TEMPLATE => 'email-cur-XXXX', TMPDIR => 1); print $ah $cur->as_string or die "print: $!"; $ah->flush or die "flush: $!"; PublicInbox::Import::drop_unwanted_headers($new); - my $bh = File::Temp->new(TEMPLATE => 'email-new-XXXXXXXX', TMPDIR => 1); + my $bh = File::Temp->new(TEMPLATE => 'email-new-XXXX', TMPDIR => 1); print $bh $new->as_string or die "print: $!"; $bh->flush or die "flush: $!"; my $cmd = [ qw(diff -u), $ah->filename, $bh->filename ]; diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm index e2d67f6a..9791f02c 100644 --- a/lib/PublicInbox/Xapcmd.pm +++ b/lib/PublicInbox/Xapcmd.pm @@ -192,7 +192,7 @@ sub prepare_run { my $dir = dirname($old); same_fs_or_die($dir, $old); my $v = PublicInbox::Search::SCHEMA_VERSION(); - my $wip = File::Temp->newdir("xapian$v-XXXXXXXX", DIR => $dir); + my $wip = File::Temp->newdir("xapian$v-XXXX", DIR => $dir); $tmp->{$old} = $wip; nodatacow_dir($wip->dirname); push @queue, [ $old, $wip ]; @@ -220,8 +220,7 @@ sub prepare_run { $src = [ map { "$old/$_" } @old_shards ]; } foreach my $dn (0..$max_shard) { - my $tmpl = "$dn-XXXXXXXX"; - my $wip = File::Temp->newdir($tmpl, DIR => $old); + my $wip = File::Temp->newdir("$dn-XXXX", DIR => $old); same_fs_or_die($old, $wip->dirname); my $cur = "$old/$dn"; push @queue, [ $src // $cur , $wip ]; @@ -291,7 +290,7 @@ sub cpdb_retryable ($$) { } sub progress_pfx ($) { - my ($wip) = @_; # tempdir v2: ([0-9])+-XXXXXXXX + my ($wip) = @_; # tempdir v2: ([0-9])+-XXXX my @p = split('/', $wip); # return "xap15/0" for v2, or "xapian15" for v1: @@ -418,7 +417,7 @@ sub cpdb ($$) { # cb_spawn callback if ($opt->{compact}) { my $dir = dirname($new); same_fs_or_die($dir, $new); - $ft = File::Temp->newdir("$new.compact-XXXXXX", DIR => $dir); + $ft = File::Temp->newdir("$new.compact-XXXX", DIR => $dir); setup_signals(); $tmp = $ft->dirname; nodatacow_dir($tmp); diff --git a/script/public-inbox-edit b/script/public-inbox-edit index 1c6c4e4a..9498038b 100755 --- a/script/public-inbox-edit +++ b/script/public-inbox-edit @@ -133,7 +133,7 @@ $mids } my %tmpopt = ( - TEMPLATE => 'public-inbox-edit-XXXXXX', + TEMPLATE => 'public-inbox-edit-XXXX', TMPDIR => 1, SUFFIX => $opt->{raw} ? '.eml' : '.mbox', ); diff --git a/script/public-inbox-init b/script/public-inbox-init index e93cab73..335eb476 100755 --- a/script/public-inbox-init +++ b/script/public-inbox-init @@ -79,7 +79,7 @@ PublicInbox::Lock::lock_acquire($lock_obj); # git-config will operate on this (and rename on success): require File::Temp; -my $fh = File::Temp->new(TEMPLATE => 'pi-init-XXXXXXXX', DIR => $dir); +my $fh = File::Temp->new(TEMPLATE => 'pi-init-XXXX', DIR => $dir); # Now, we grab another lock to use git-config(1) locking, so it won't # wait on the lock, unlike some of our internal flock()-based locks. diff --git a/scripts/ssoma-replay b/scripts/ssoma-replay index cfb0fbd9..70d0081d 100755 --- a/scripts/ssoma-replay +++ b/scripts/ssoma-replay @@ -29,7 +29,7 @@ use strict; use Email::Simple; use URI::Escape qw/uri_escape_utf8/; use File::Temp qw/tempfile/; -my ($fh, $filename) = tempfile('ssoma-replay-XXXXXXXX', TMPDIR => 1); +my ($fh, $filename) = tempfile('ssoma-replay-XXXX', TMPDIR => 1); my $msg = Email::Simple->new(do { local $/; }); select $fh; diff --git a/t/check-www-inbox.perl b/t/check-www-inbox.perl index eee8adc2..033b90d1 100644 --- a/t/check-www-inbox.perl +++ b/t/check-www-inbox.perl @@ -91,7 +91,7 @@ foreach my $p (1..$nproc) { } } -my ($fh, $tmp) = tempfile('www-check-XXXXXXXX', +my ($fh, $tmp) = tempfile('www-check-XXXX', SUFFIX => '.gdbm', UNLINK => 1, TMPDIR => 1); my $gdbm = tie my %seen, 'GDBM_File', $tmp, &GDBM_WRCREAT, 0600; defined $gdbm or die "gdbm open failed: $!\n"; diff --git a/t/inbox.t b/t/inbox.t index b7239e6d..0580cd23 100644 --- a/t/inbox.t +++ b/t/inbox.t @@ -13,7 +13,7 @@ is($x->base_url, 'http://example.com/test/', 'added trailing slash'); $x = PublicInbox::Inbox->new({}); is($x->base_url, undef, 'undef base_url allowed'); -my $tmpdir = File::Temp->newdir('pi-inbox-XXXXXX', TMPDIR => 1); +my $tmpdir = File::Temp->newdir('pi-inbox-XXXX', TMPDIR => 1); $x->{inboxdir} = $tmpdir->dirname; is_deeply($x->cloneurl, [], 'no cloneurls'); is($x->description, '($INBOX_DIR/description missing)', 'default description'); diff --git a/t/nodatacow.t b/t/nodatacow.t index 72860d43..9b67c521 100644 --- a/t/nodatacow.t +++ b/t/nodatacow.t @@ -15,7 +15,7 @@ SKIP: { skip 'BTRFS_TESTDIR not defined', $nr unless defined $dir; skip 'chattr(1) not installed', $nr unless which('chattr'); my $lsattr = which('lsattr') or skip 'lsattr(1) not installed', $nr; - my $tmp = File::Temp->newdir('nodatacow-XXXXX', DIR => $dir); + my $tmp = File::Temp->newdir('nodatacow-XXXX', DIR => $dir); my $dn = $tmp->dirname; my $name = "$dn/pp.f";