1211963Sbrian# $FreeBSD$ 2211963Sbrian 3211963Sbrianuse strict; 4211963Sbrianuse warnings; 5211963Sbrian 6211963Sbrianuse Test::More tests => 6; 7211963Sbrianuse File::Path qw(rmtree mkpath); 8211963Sbrianuse Cwd; 9211963Sbrian 10211963Sbrianmy $n = 0; 11211963Sbriansub create_file { 12211963Sbrian my $fn = shift; 13211963Sbrian 14211963Sbrian $n++; 15211963Sbrian (my $dir = $fn) =~ s,/[^/]+$,,; 16211963Sbrian mkpath $dir; 17211963Sbrian open my $fd, ">", $fn or die "$fn: $!"; 18211963Sbrian print $fd "file $n\n"; 19211963Sbrian} 20211963Sbrian 21211963Sbrian 22211963Sbrianustar_pathnames: { SKIP: { 23211963Sbrian # Prove that pax breaks up ustar pathnames properly 24211963Sbrian 25211963Sbrian my $top = getcwd . "/ustar-pathnames-1"; 26211963Sbrian skip "Current path is too long", 6 if length $top > 92; 27211963Sbrian rmtree $top; 28211963Sbrian my $subdir = "x" . "x" x (92 - length $top); 29211963Sbrian my $work94 = "$top/$subdir"; 30211963Sbrian mkpath $work94; # $work is 94 characters long 31211963Sbrian 32211963Sbrian my $x49 = "x" x 49; 33211963Sbrian my $x50 = "x" x 50; 34211963Sbrian my $x60 = "x" x 60; 35211963Sbrian my $x95 = "x" x 95; 36211963Sbrian 37211963Sbrian my @paths = ( 38211963Sbrian "$work94/x099", # 99 chars 39211963Sbrian "$work94/xx100", # 100 chars 40211963Sbrian "$work94/xxx101", # 101 chars 41211963Sbrian "$work94/$x49/${x50}x199", # 199 chars 42211963Sbrian "$work94/$x49/${x50}xx200", # 200 chars 43211963Sbrian "$work94/$x49/${x50}xxx201", # 201 chars 44211963Sbrian "$work94/$x60/${x95}254", # 254 chars 45211963Sbrian "$work94/$x60/${x95}x255", # 255 chars 46211963Sbrian ); 47211963Sbrian 48211963Sbrian my @l = map { length } @paths; 49211963Sbrian 50211963Sbrian my $n = 0; 51211963Sbrian create_file $_ for @paths; 52211963Sbrian system "pax -wf ustar.ok $work94"; 53211963Sbrian ok($? == 0, "Wrote 'ustar.ok' containing files with lengths @l"); 54211963Sbrian 55211963Sbrian (my $orig = $top) =~ s,1$,2,; 56211963Sbrian rmtree $orig; 57211963Sbrian rename $top, $orig; 58211963Sbrian 59211963Sbrian system "pax -rf ustar.ok"; 60211963Sbrian ok($? == 0, "Restored 'ustar.ok' containing files with lengths @l"); 61211963Sbrian 62211963Sbrian system "diff -ru $orig $top"; 63211963Sbrian ok($? == 0, "Restored files are identical"); 64211963Sbrian 65211963Sbrian rmtree $top; 66211963Sbrian rename $orig, $top; 67211963Sbrian 68211963Sbrian # 256 chars (with components < 100 chars) should not work 69211963Sbrian push @paths, "$work94/x$x60/${x95}x256"; # 256 chars 70211963Sbrian push @l, length $paths[-1]; 71211963Sbrian create_file $paths[-1]; 72211963Sbrian system "pax -wf ustar.fail1 $work94"; 73211963Sbrian ok($?, "Failed to write 'ustar.fail1' containing files with lengths @l"); 74211963Sbrian 75211963Sbrian # Components with 100 chars shouldn't work 76211963Sbrian unlink $paths[-1]; 77211963Sbrian $paths[-1] = "$work94/${x95}xc100"; # 100 char filename 78211963Sbrian $l[-1] = length $paths[-1]; 79211963Sbrian create_file $paths[-1]; 80211963Sbrian system "pax -wf ustar.fail2 $work94"; 81211963Sbrian ok($?, "Failed to write 'ustar.fail2' with a 100 char filename"); 82211963Sbrian 83211963Sbrian unlink $paths[-1]; 84211963Sbrian $paths[-1] = "$work94/${x95}xc100/x"; # 100 char component 85211963Sbrian $l[-1] = length $paths[-1]; 86211963Sbrian create_file $paths[-1]; 87211963Sbrian system "pax -wf ustar.fail3 $work94"; 88211963Sbrian ok($?, "Failed to write 'ustar.fail3' with a 100 char component"); 89211963Sbrian}} 90