Run each Coreutils.pm-based test in its own subdirectory.
* tests/CuTmpdir.pm: New file.
* tests/Makefile.am (EXTRA_DIST): Add CuTmpdir.pm.
* tests/misc/od, tests/misc/base64, tests/misc/basename:
* tests/misc/cut, tests/misc/date, tests/misc/dirname:
* tests/misc/expand, tests/misc/fold, tests/misc/head-elide-tail:
* tests/misc/paste-no-nl, tests/misc/pr, tests/misc/sha224sum:
* tests/misc/sha256sum, tests/misc/sha384sum, tests/misc/sha512sum:
* tests/misc/sort-merge, tests/misc/stat-printf, tests/misc/test-diag:
* tests/misc/wc-files0-from, tests/misc/xstrtol:
* tests/dd/skip-seek, tests/dircolors/simple, tests/du/files0-from:
* tests/expr/basic, tests/factor/basic, tests/fmt/basic:
* tests/ls-2/tests, tests/md5sum/basic-1, tests/md5sum/newline-1:
* tests/seq/basic, tests/sha1sum/basic-1, tests/sha1sum/sample-vec:
* tests/sum/basic-1, tests/tsort/basic-1, tests/unexpand/basic-1:
* tests/mv/i-1, tests/rm/empty-name, tests/rm/unreadable: Use it.
* tests/misc/test-diag: Use "$ENV{abs_top_builddir}/src/test",
not "../../src/test", so it works when run from a subdirectory.
* tests/ls-2/tests: Create temp files and dirs from within the perl
script, so that they're removed, when run from a subdirectory.
2007-08-18 08:50:00 +02:00
|
|
|
package CuTmpdir;
|
|
|
|
|
# create, then chdir into a temporary sub-directory
|
|
|
|
|
|
2025-01-01 09:14:56 +00:00
|
|
|
# Copyright (C) 2007-2025 Free Software Foundation, Inc.
|
Run each Coreutils.pm-based test in its own subdirectory.
* tests/CuTmpdir.pm: New file.
* tests/Makefile.am (EXTRA_DIST): Add CuTmpdir.pm.
* tests/misc/od, tests/misc/base64, tests/misc/basename:
* tests/misc/cut, tests/misc/date, tests/misc/dirname:
* tests/misc/expand, tests/misc/fold, tests/misc/head-elide-tail:
* tests/misc/paste-no-nl, tests/misc/pr, tests/misc/sha224sum:
* tests/misc/sha256sum, tests/misc/sha384sum, tests/misc/sha512sum:
* tests/misc/sort-merge, tests/misc/stat-printf, tests/misc/test-diag:
* tests/misc/wc-files0-from, tests/misc/xstrtol:
* tests/dd/skip-seek, tests/dircolors/simple, tests/du/files0-from:
* tests/expr/basic, tests/factor/basic, tests/fmt/basic:
* tests/ls-2/tests, tests/md5sum/basic-1, tests/md5sum/newline-1:
* tests/seq/basic, tests/sha1sum/basic-1, tests/sha1sum/sample-vec:
* tests/sum/basic-1, tests/tsort/basic-1, tests/unexpand/basic-1:
* tests/mv/i-1, tests/rm/empty-name, tests/rm/unreadable: Use it.
* tests/misc/test-diag: Use "$ENV{abs_top_builddir}/src/test",
not "../../src/test", so it works when run from a subdirectory.
* tests/ls-2/tests: Create temp files and dirs from within the perl
script, so that they're removed, when run from a subdirectory.
2007-08-18 08:50:00 +02:00
|
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2017-09-19 01:13:23 -07:00
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
Run each Coreutils.pm-based test in its own subdirectory.
* tests/CuTmpdir.pm: New file.
* tests/Makefile.am (EXTRA_DIST): Add CuTmpdir.pm.
* tests/misc/od, tests/misc/base64, tests/misc/basename:
* tests/misc/cut, tests/misc/date, tests/misc/dirname:
* tests/misc/expand, tests/misc/fold, tests/misc/head-elide-tail:
* tests/misc/paste-no-nl, tests/misc/pr, tests/misc/sha224sum:
* tests/misc/sha256sum, tests/misc/sha384sum, tests/misc/sha512sum:
* tests/misc/sort-merge, tests/misc/stat-printf, tests/misc/test-diag:
* tests/misc/wc-files0-from, tests/misc/xstrtol:
* tests/dd/skip-seek, tests/dircolors/simple, tests/du/files0-from:
* tests/expr/basic, tests/factor/basic, tests/fmt/basic:
* tests/ls-2/tests, tests/md5sum/basic-1, tests/md5sum/newline-1:
* tests/seq/basic, tests/sha1sum/basic-1, tests/sha1sum/sample-vec:
* tests/sum/basic-1, tests/tsort/basic-1, tests/unexpand/basic-1:
* tests/mv/i-1, tests/rm/empty-name, tests/rm/unreadable: Use it.
* tests/misc/test-diag: Use "$ENV{abs_top_builddir}/src/test",
not "../../src/test", so it works when run from a subdirectory.
* tests/ls-2/tests: Create temp files and dirs from within the perl
script, so that they're removed, when run from a subdirectory.
2007-08-18 08:50:00 +02:00
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
|
|
use File::Temp;
|
2007-09-16 11:07:59 +02:00
|
|
|
use File::Find;
|
Run each Coreutils.pm-based test in its own subdirectory.
* tests/CuTmpdir.pm: New file.
* tests/Makefile.am (EXTRA_DIST): Add CuTmpdir.pm.
* tests/misc/od, tests/misc/base64, tests/misc/basename:
* tests/misc/cut, tests/misc/date, tests/misc/dirname:
* tests/misc/expand, tests/misc/fold, tests/misc/head-elide-tail:
* tests/misc/paste-no-nl, tests/misc/pr, tests/misc/sha224sum:
* tests/misc/sha256sum, tests/misc/sha384sum, tests/misc/sha512sum:
* tests/misc/sort-merge, tests/misc/stat-printf, tests/misc/test-diag:
* tests/misc/wc-files0-from, tests/misc/xstrtol:
* tests/dd/skip-seek, tests/dircolors/simple, tests/du/files0-from:
* tests/expr/basic, tests/factor/basic, tests/fmt/basic:
* tests/ls-2/tests, tests/md5sum/basic-1, tests/md5sum/newline-1:
* tests/seq/basic, tests/sha1sum/basic-1, tests/sha1sum/sample-vec:
* tests/sum/basic-1, tests/tsort/basic-1, tests/unexpand/basic-1:
* tests/mv/i-1, tests/rm/empty-name, tests/rm/unreadable: Use it.
* tests/misc/test-diag: Use "$ENV{abs_top_builddir}/src/test",
not "../../src/test", so it works when run from a subdirectory.
* tests/ls-2/tests: Create temp files and dirs from within the perl
script, so that they're removed, when run from a subdirectory.
2007-08-18 08:50:00 +02:00
|
|
|
|
|
|
|
|
our $ME = $0 || "<???>";
|
|
|
|
|
|
|
|
|
|
my $dir;
|
|
|
|
|
|
2008-04-25 10:41:42 +02:00
|
|
|
sub skip_test($)
|
2007-09-16 11:07:59 +02:00
|
|
|
{
|
2012-01-07 20:55:10 +01:00
|
|
|
warn "$ME: skipping test: unsafe working directory name: '$_[0]'\n";
|
2007-09-16 11:07:59 +02:00
|
|
|
exit 77;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-25 10:41:42 +02:00
|
|
|
sub chmod_1
|
|
|
|
|
{
|
|
|
|
|
my $name = $_;
|
|
|
|
|
|
|
|
|
|
# Skip symlinks and non-directories.
|
|
|
|
|
-l $name || !-d _
|
|
|
|
|
and return;
|
|
|
|
|
|
|
|
|
|
chmod 0700, $name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub chmod_tree
|
|
|
|
|
{
|
2009-03-25 10:15:46 +01:00
|
|
|
# When tempdir fails, it croaks, which leaves $dir undefined.
|
|
|
|
|
defined $dir
|
|
|
|
|
or return;
|
|
|
|
|
|
2009-04-22 21:41:10 +02:00
|
|
|
# Perform the equivalent of find "$dir" -type d -print0|xargs -0 chmod -R 700.
|
|
|
|
|
my $options = {untaint => 1, wanted => \&chmod_1};
|
|
|
|
|
find ($options, $dir);
|
2008-04-25 10:41:42 +02:00
|
|
|
}
|
|
|
|
|
|
Run each Coreutils.pm-based test in its own subdirectory.
* tests/CuTmpdir.pm: New file.
* tests/Makefile.am (EXTRA_DIST): Add CuTmpdir.pm.
* tests/misc/od, tests/misc/base64, tests/misc/basename:
* tests/misc/cut, tests/misc/date, tests/misc/dirname:
* tests/misc/expand, tests/misc/fold, tests/misc/head-elide-tail:
* tests/misc/paste-no-nl, tests/misc/pr, tests/misc/sha224sum:
* tests/misc/sha256sum, tests/misc/sha384sum, tests/misc/sha512sum:
* tests/misc/sort-merge, tests/misc/stat-printf, tests/misc/test-diag:
* tests/misc/wc-files0-from, tests/misc/xstrtol:
* tests/dd/skip-seek, tests/dircolors/simple, tests/du/files0-from:
* tests/expr/basic, tests/factor/basic, tests/fmt/basic:
* tests/ls-2/tests, tests/md5sum/basic-1, tests/md5sum/newline-1:
* tests/seq/basic, tests/sha1sum/basic-1, tests/sha1sum/sample-vec:
* tests/sum/basic-1, tests/tsort/basic-1, tests/unexpand/basic-1:
* tests/mv/i-1, tests/rm/empty-name, tests/rm/unreadable: Use it.
* tests/misc/test-diag: Use "$ENV{abs_top_builddir}/src/test",
not "../../src/test", so it works when run from a subdirectory.
* tests/ls-2/tests: Create temp files and dirs from within the perl
script, so that they're removed, when run from a subdirectory.
2007-08-18 08:50:00 +02:00
|
|
|
sub import {
|
|
|
|
|
my $prefix = $_[1];
|
2007-11-30 13:40:25 +01:00
|
|
|
|
|
|
|
|
$ME eq '-' && defined $prefix
|
|
|
|
|
and $ME = $prefix;
|
|
|
|
|
|
Run each Coreutils.pm-based test in its own subdirectory.
* tests/CuTmpdir.pm: New file.
* tests/Makefile.am (EXTRA_DIST): Add CuTmpdir.pm.
* tests/misc/od, tests/misc/base64, tests/misc/basename:
* tests/misc/cut, tests/misc/date, tests/misc/dirname:
* tests/misc/expand, tests/misc/fold, tests/misc/head-elide-tail:
* tests/misc/paste-no-nl, tests/misc/pr, tests/misc/sha224sum:
* tests/misc/sha256sum, tests/misc/sha384sum, tests/misc/sha512sum:
* tests/misc/sort-merge, tests/misc/stat-printf, tests/misc/test-diag:
* tests/misc/wc-files0-from, tests/misc/xstrtol:
* tests/dd/skip-seek, tests/dircolors/simple, tests/du/files0-from:
* tests/expr/basic, tests/factor/basic, tests/fmt/basic:
* tests/ls-2/tests, tests/md5sum/basic-1, tests/md5sum/newline-1:
* tests/seq/basic, tests/sha1sum/basic-1, tests/sha1sum/sample-vec:
* tests/sum/basic-1, tests/tsort/basic-1, tests/unexpand/basic-1:
* tests/mv/i-1, tests/rm/empty-name, tests/rm/unreadable: Use it.
* tests/misc/test-diag: Use "$ENV{abs_top_builddir}/src/test",
not "../../src/test", so it works when run from a subdirectory.
* tests/ls-2/tests: Create temp files and dirs from within the perl
script, so that they're removed, when run from a subdirectory.
2007-08-18 08:50:00 +02:00
|
|
|
if ($prefix !~ /^\//)
|
|
|
|
|
{
|
|
|
|
|
eval 'use Cwd';
|
|
|
|
|
my $cwd = $@ ? '.' : Cwd::getcwd();
|
|
|
|
|
$prefix = "$cwd/$prefix";
|
|
|
|
|
}
|
2007-09-16 11:07:59 +02:00
|
|
|
|
|
|
|
|
# Untaint for the upcoming mkdir.
|
|
|
|
|
$prefix =~ m!^([-+\@\w./]+)$!
|
2008-04-25 10:41:42 +02:00
|
|
|
or skip_test $prefix;
|
2007-09-16 11:07:59 +02:00
|
|
|
$prefix = $1;
|
|
|
|
|
|
2008-04-28 10:30:22 -04:00
|
|
|
my $original_pid = $$;
|
|
|
|
|
|
|
|
|
|
my $on_sig_remove_tmpdir = sub {
|
|
|
|
|
my ($sig) = @_;
|
|
|
|
|
if ($$ == $original_pid and defined $dir)
|
|
|
|
|
{
|
2009-08-22 18:56:06 +02:00
|
|
|
chmod_tree;
|
|
|
|
|
# Older versions of File::Temp lack this method.
|
|
|
|
|
exists &File::Temp::cleanup
|
|
|
|
|
and &File::Temp::cleanup;
|
2008-04-28 10:30:22 -04:00
|
|
|
}
|
|
|
|
|
$SIG{$sig} = 'DEFAULT';
|
|
|
|
|
kill $sig, $$;
|
|
|
|
|
};
|
|
|
|
|
|
2008-04-25 10:41:42 +02:00
|
|
|
foreach my $sig (qw (INT TERM HUP))
|
|
|
|
|
{
|
2008-04-28 10:30:22 -04:00
|
|
|
$SIG{$sig} = $on_sig_remove_tmpdir;
|
2008-04-25 10:41:42 +02:00
|
|
|
}
|
|
|
|
|
|
Run each Coreutils.pm-based test in its own subdirectory.
* tests/CuTmpdir.pm: New file.
* tests/Makefile.am (EXTRA_DIST): Add CuTmpdir.pm.
* tests/misc/od, tests/misc/base64, tests/misc/basename:
* tests/misc/cut, tests/misc/date, tests/misc/dirname:
* tests/misc/expand, tests/misc/fold, tests/misc/head-elide-tail:
* tests/misc/paste-no-nl, tests/misc/pr, tests/misc/sha224sum:
* tests/misc/sha256sum, tests/misc/sha384sum, tests/misc/sha512sum:
* tests/misc/sort-merge, tests/misc/stat-printf, tests/misc/test-diag:
* tests/misc/wc-files0-from, tests/misc/xstrtol:
* tests/dd/skip-seek, tests/dircolors/simple, tests/du/files0-from:
* tests/expr/basic, tests/factor/basic, tests/fmt/basic:
* tests/ls-2/tests, tests/md5sum/basic-1, tests/md5sum/newline-1:
* tests/seq/basic, tests/sha1sum/basic-1, tests/sha1sum/sample-vec:
* tests/sum/basic-1, tests/tsort/basic-1, tests/unexpand/basic-1:
* tests/mv/i-1, tests/rm/empty-name, tests/rm/unreadable: Use it.
* tests/misc/test-diag: Use "$ENV{abs_top_builddir}/src/test",
not "../../src/test", so it works when run from a subdirectory.
* tests/ls-2/tests: Create temp files and dirs from within the perl
script, so that they're removed, when run from a subdirectory.
2007-08-18 08:50:00 +02:00
|
|
|
$dir = File::Temp::tempdir("$prefix.tmp-XXXX", CLEANUP => 1 );
|
|
|
|
|
chdir $dir
|
|
|
|
|
or warn "$ME: failed to chdir to $dir: $!\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
END {
|
2009-04-22 21:41:10 +02:00
|
|
|
# Move cwd out of the directory we're about to remove.
|
|
|
|
|
# This is required on some systems, and by some versions of File::Temp.
|
|
|
|
|
chdir '..'
|
|
|
|
|
or warn "$ME: failed to chdir to .. from $dir: $!\n";
|
|
|
|
|
|
Run each Coreutils.pm-based test in its own subdirectory.
* tests/CuTmpdir.pm: New file.
* tests/Makefile.am (EXTRA_DIST): Add CuTmpdir.pm.
* tests/misc/od, tests/misc/base64, tests/misc/basename:
* tests/misc/cut, tests/misc/date, tests/misc/dirname:
* tests/misc/expand, tests/misc/fold, tests/misc/head-elide-tail:
* tests/misc/paste-no-nl, tests/misc/pr, tests/misc/sha224sum:
* tests/misc/sha256sum, tests/misc/sha384sum, tests/misc/sha512sum:
* tests/misc/sort-merge, tests/misc/stat-printf, tests/misc/test-diag:
* tests/misc/wc-files0-from, tests/misc/xstrtol:
* tests/dd/skip-seek, tests/dircolors/simple, tests/du/files0-from:
* tests/expr/basic, tests/factor/basic, tests/fmt/basic:
* tests/ls-2/tests, tests/md5sum/basic-1, tests/md5sum/newline-1:
* tests/seq/basic, tests/sha1sum/basic-1, tests/sha1sum/sample-vec:
* tests/sum/basic-1, tests/tsort/basic-1, tests/unexpand/basic-1:
* tests/mv/i-1, tests/rm/empty-name, tests/rm/unreadable: Use it.
* tests/misc/test-diag: Use "$ENV{abs_top_builddir}/src/test",
not "../../src/test", so it works when run from a subdirectory.
* tests/ls-2/tests: Create temp files and dirs from within the perl
script, so that they're removed, when run from a subdirectory.
2007-08-18 08:50:00 +02:00
|
|
|
my $saved_errno = $?;
|
2008-04-25 10:41:42 +02:00
|
|
|
chmod_tree;
|
Run each Coreutils.pm-based test in its own subdirectory.
* tests/CuTmpdir.pm: New file.
* tests/Makefile.am (EXTRA_DIST): Add CuTmpdir.pm.
* tests/misc/od, tests/misc/base64, tests/misc/basename:
* tests/misc/cut, tests/misc/date, tests/misc/dirname:
* tests/misc/expand, tests/misc/fold, tests/misc/head-elide-tail:
* tests/misc/paste-no-nl, tests/misc/pr, tests/misc/sha224sum:
* tests/misc/sha256sum, tests/misc/sha384sum, tests/misc/sha512sum:
* tests/misc/sort-merge, tests/misc/stat-printf, tests/misc/test-diag:
* tests/misc/wc-files0-from, tests/misc/xstrtol:
* tests/dd/skip-seek, tests/dircolors/simple, tests/du/files0-from:
* tests/expr/basic, tests/factor/basic, tests/fmt/basic:
* tests/ls-2/tests, tests/md5sum/basic-1, tests/md5sum/newline-1:
* tests/seq/basic, tests/sha1sum/basic-1, tests/sha1sum/sample-vec:
* tests/sum/basic-1, tests/tsort/basic-1, tests/unexpand/basic-1:
* tests/mv/i-1, tests/rm/empty-name, tests/rm/unreadable: Use it.
* tests/misc/test-diag: Use "$ENV{abs_top_builddir}/src/test",
not "../../src/test", so it works when run from a subdirectory.
* tests/ls-2/tests: Create temp files and dirs from within the perl
script, so that they're removed, when run from a subdirectory.
2007-08-18 08:50:00 +02:00
|
|
|
$? = $saved_errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
1;
|