]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
test_common: symlink xap_helper instead of excessive copying
authorEric Wong <e@80x24.org>
Sun, 1 Jun 2025 10:14:47 +0000 (10:14 +0000)
committerEric Wong <e@80x24.org>
Sun, 1 Jun 2025 10:15:49 +0000 (10:15 +0000)
Copying the entire directory is racy in the face of parallel
tests and caused an occasional test failure due to attempts (and
failures) in copying short-lived temporary files.  A symlink
for just the executable avoids attempted copies temporary files
is less expensive for the intended file, as well.

lib/PublicInbox/TestCommon.pm

index e0274610d36e588abfb70a48e1c3e9a2b4737420..fe81b30599f419d179e87ee0b13f1cfb6ca7002f 100644 (file)
@@ -16,7 +16,7 @@ our @EXPORT;
 my $lei_loud = $ENV{TEST_LEI_ERR_LOUD};
 our $tail_cmd = $ENV{TAIL};
 our ($lei_opt, $lei_out, $lei_err, $find_xh_pid);
-use autodie qw(chdir close fcntl mkdir open opendir seek unlink);
+use autodie qw(chdir close fcntl mkdir open opendir seek symlink unlink);
 $ENV{XDG_CACHE_HOME} //= "$ENV{HOME}/.cache"; # reuse C++ xap_helper builds
 $ENV{GIT_TEST_FSYNC} = 0; # hopefully reduce wear
 
@@ -783,12 +783,12 @@ SKIP: {
                my $home = "$tmpdir/lei-daemon";
                mkdir($home, 0700);
                local $ENV{HOME} = $home;
-               if ($xh_cmd && $xh_cmd->[0] =~ m!\A(.+)/+[^/]+\z!) {
-                       # avoid repeated rebuilds by copying
-                       my $src = $1;
+               if ($xh_cmd && $xh_cmd->[0] =~ m!\A.+/+([^/]+)\z!) {
+                       # avoid repeated rebuilds by symlinking
+                       my ($src, $bn) = ($xh_cmd->[0], $1);
                        my $dst = "$home/.cache/public-inbox/jaot";
                        File::Path::make_path($dst);
-                       xsys_e([qw(/bin/cp -Rp), $src, $dst ]);
+                       symlink $src, "$dst/$bn";
                }
                my $persist;
                if ($persist_xrd && !$test_opt->{daemon_only}) {