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