xref: /freebsd/bin/pax/tests/legacy_test.pl (revision aa1207ea4f030c50a91bca6a3df950ca25113d5a)
1
2use strict;
3use warnings;
4
5use Test::More tests => 6;
6use File::Path qw(rmtree mkpath);
7use Cwd;
8
9my $n = 0;
10sub create_file {
11    my $fn = shift;
12
13    $n++;
14    (my $dir = $fn) =~ s,/[^/]+$,,;
15    mkpath $dir;
16    open my $fd, ">", $fn or die "$fn: $!";
17    print $fd "file $n\n";
18}
19
20
21ustar_pathnames: { SKIP: {
22    # Prove that pax breaks up ustar pathnames properly
23
24    my $top = getcwd . "/ustar-pathnames-1";
25    skip "Current path is too long", 6 if length $top > 92;
26    rmtree $top;
27    my $subdir = "x" . "x" x (92 - length $top);
28    my $work94 = "$top/$subdir";
29    mkpath $work94;		# $work is 94 characters long
30
31    my $x49 = "x" x 49;
32    my $x50 = "x" x 50;
33    my $x60 = "x" x 60;
34    my $x95 = "x" x 95;
35
36    my @paths = (
37	"$work94/x099",		# 99 chars
38	"$work94/xx100",		# 100 chars
39	"$work94/xxx101",		# 101 chars
40	"$work94/$x49/${x50}x199",	# 199 chars
41	"$work94/$x49/${x50}xx200",	# 200 chars
42	"$work94/$x49/${x50}xxx201",	# 201 chars
43	"$work94/$x60/${x95}254",	# 254 chars
44	"$work94/$x60/${x95}x255",	# 255 chars
45    );
46
47    my @l = map { length } @paths;
48
49    my $n = 0;
50    create_file $_ for @paths;
51    system "pax -wf ustar.ok $work94";
52    ok($? == 0, "Wrote 'ustar.ok' containing files with lengths @l");
53
54    (my $orig = $top) =~ s,1$,2,;
55    rmtree $orig;
56    rename $top, $orig;
57
58    system "pax -rf ustar.ok";
59    ok($? == 0, "Restored 'ustar.ok' containing files with lengths @l");
60
61    system "diff -ru $orig $top";
62    ok($? == 0, "Restored files are identical");
63
64    rmtree $top;
65    rename $orig, $top;
66
67    # 256 chars (with components < 100 chars) should not work
68    push @paths, "$work94/x$x60/${x95}x256";	# 256 chars
69    push @l, length $paths[-1];
70    create_file $paths[-1];
71    system "pax -wf ustar.fail1 $work94";
72    ok($?, "Failed to write 'ustar.fail1' containing files with lengths @l");
73
74    # Components with 100 chars shouldn't work
75    unlink $paths[-1];
76    $paths[-1] = "$work94/${x95}xc100";		# 100 char filename
77    $l[-1] = length $paths[-1];
78    create_file $paths[-1];
79    system "pax -wf ustar.fail2 $work94";
80    ok($?, "Failed to write 'ustar.fail2' with a 100 char filename");
81
82    unlink $paths[-1];
83    $paths[-1] = "$work94/${x95}xc100/x";	# 100 char component
84    $l[-1] = length $paths[-1];
85    create_file $paths[-1];
86    system "pax -wf ustar.fail3 $work94";
87    ok($?, "Failed to write 'ustar.fail3' with a 100 char component");
88}}
89