pod2usage(-exitval => 0, -verbose => 2) if $MAN;
list_test(), exit 0 if $LIST_TEST;
-if($USER xor $PW) {
+if ($USER xor $PW) {
die "Need both user and password when one is provided\n";
-} elsif($USER and $PW) {
+}
+elsif ($USER and $PW) {
push @SMBARGS, '-U'.$USER.'%'.$PW;
-} else {
+}
+else {
push @SMBARGS, '-N';
}
-if($IP) {
+if ($IP) {
push @SMBARGS, '-I', $IP;
}
# path to store the downloaded tarball
my $TAR = "$TMP/tarmode.tar";
-if($CLEAN) {
+if ($CLEAN) {
# clean the whole root first
remove_tree($LOCALPATH, { keep_root => 1 });
}
# RUN TESTS
-if($SINGLE_TEST == -1) {
+if ($SINGLE_TEST == -1) {
run_test(@TESTS);
-}
-
-elsif(0 <= $SINGLE_TEST && $SINGLE_TEST < @TESTS) {
+} elsif (0 <= $SINGLE_TEST && $SINGLE_TEST < @TESTS) {
run_test($TESTS[$SINGLE_TEST]);
-}
-
-else {
+} else {
die "Test number is invalid\n";
}
# combinations of attributes
for my $n (1..@attr) {
- for(combine(\@attr, $n)) {
+ for (combine(\@attr, $n)) {
my @t = @$_;
my $fn = "file-" . join('+', @t) . ".txt";
my $f = File->new_remote($fn);
my @files;
my $n = 3;
- for(1..$n) {
+ for (1..$n) {
my $f = File->new_remote("file-$_");
$f->set_attr('a');
push @files, $f;
}
- if($mode =~ /reset/) {
+ if ($mode =~ /reset/) {
smb_tar('tarmode full reset', '-Tc', $TAR, $DIR);
} else {
smb_tar('', '-Tca', $TAR, $DIR);
}
my $err = check_tar($TAR, \@files);
- return $err if($err > 0);
+ return $err if ($err > 0);
for my $f (File::list($DIR)) {
- if($f->{attr}{a}) {
+ if ($f->{attr}{a}) {
printf " ! %s %s\n", $f->attr_str, $f->remotepath;
$err++;
}
my $prefix = ($mode =~ /nest/) ? "/foo/bar/bar/" : '';
my @files;
my $n = 5;
- for(1..$n) {
+ for (1..$n) {
my $f = File->new_remote($prefix."file-$_");
push @files, $f;
}
my @files;
my $n = 10;
- for(1..$n) {
+ for (1..$n) {
my $f = File->new_remote("file-$_");
# set archive bit on ~half of them
- if($_ < $n/2) {
+ if ($_ < $n/2) {
$f->set_attr('a');
push @files, $f;
}
}
}
- if($mode =~ /inc/) {
+ if ($mode =~ /inc/) {
smb_tar('tarmode inc', '-Tc', $TAR, $DIR);
} else {
smb_tar('', '-Tcg', $TAR, $DIR);
sub test_extraction_normal {
my @files;
my $n = 5;
- for(1..$n) {
+ for (1..$n) {
my $f = File->new_remote("file-$_");
push @files, $f;
}
my @all_files;
my @inc_files;
- for(qw(file_inc inc/b inc/c inc/dir/foo dir_ex/d zob)) {
+ for (qw(file_inc inc/b inc/c inc/dir/foo dir_ex/d zob)) {
my $f = File->new_remote($_);
push @all_files, $f;
push @inc_files, $f if /inc/;
my @all_files;
my @inc_files;
- for(qw(file_exc exc/b exc/c exc/dir/foo dir_ex/d zob)) {
+ for (qw(file_exc exc/b exc/c exc/dir/foo dir_ex/d zob)) {
my $f = File->new_remote($_);
push @all_files, $f;
push @inc_files, $f if !/exc/;
sub test_creation_include {
my @files;
- for(qw(file_inc inc/b inc/c inc/dir/foo dir_ex/d zob)) {
+ for (qw(file_inc inc/b inc/c inc/dir/foo dir_ex/d zob)) {
my $f = File->new_remote($_);
push @files, $f if /inc/;
}
sub test_creation_exclude {
my @files;
- for(qw(file_ex ex/b ex/c ex/dir/foo foo/bar zob)) {
+ for (qw(file_ex ex/b ex/c ex/dir/foo foo/bar zob)) {
my $f = File->new_remote($_);
push @files, $f if !/ex/;
}
sub test_creation_list {
my @inc_files;
- for(qw(file_inc inc/b inc/c inc/dir/foo foo/bar zob)) {
+ for (qw(file_inc inc/b inc/c inc/dir/foo foo/bar zob)) {
my $f = File->new_remote($_);
push @inc_files, $f if /inc/;
}
$nb = 0;
for my $dir (@dirs) {
- for(@exts) {
+ for (@exts) {
my $fn = $dir . "file$nb." . $_;
my $f = File->new_remote($fn, 'ABSPATH');
$f->delete_on_destruction(1);
$nb = 0;
for my $dir (@dirs) {
- for(@exts) {
+ for (@exts) {
my $fn = $dir . "file$nb." . $_;
my $f = File->new_remote($fn, 'ABSPATH');
$f->delete_on_destruction(1);
my @inc_files;
my @all_files;
- for(qw(file_inc inc/b inc/c inc/dir/foo foo/bar zob)) {
+ for (qw(file_inc inc/b inc/c inc/dir/foo foo/bar zob)) {
my $f = File->new_remote($_);
push @all_files, $f;
push @inc_files, $f if /inc/;
# list test number and description
sub list_test {
my $i = 0;
- for(@TESTS) {
+ for (@TESTS) {
my ($desc, $f, @args) = @$_;
printf "%2d.\t%s\n", $i++, $desc;
}
}
sub run_test {
- for(@_) {
+ for (@_) {
my ($desc, $f, @args) = @$_;
reset_env();
say "TEST: $desc";
sub print_res {
my $err = shift;
- if($err) {
+ if ($err) {
printf " RES: %s%d ERR%s\n", color('bold red'), $err, color 'reset';
} else {
printf " RES: %sOK%s\n", color('bold green'), color 'reset';
sub file_list {
my @files = @_;
my $s = '';
- for(@files) {
+ for (@files) {
$s .= $_->remotepath."\n";
}
return $s;
my (%done, %expected);
my (@less, @more, @diff);
- for(@$files) {
+ for (@$files) {
$expected{$_->remotepath} = $_;
$done{$_->remotepath} = 0;
}
for my $rfile (keys %remote) {
# files that shouldn't be there
- if(!exists $expected{$rfile}) {
+ if (!exists $expected{$rfile}) {
say " + $rfile";
push @more, $rfile;
next;
}
# same file multiple times
- if($done{$rfile} > 0) {
+ if ($done{$rfile} > 0) {
$done{$rfile}++;
push @more, $rfile;
printf " +%3d %s\n", $done{$rfile}, $rfile;
# different file
my $rmd5 = $remote{$rfile}->md5;
- if($expected{$rfile}->md5 ne $rmd5) {
+ if ($expected{$rfile}->md5 ne $rmd5) {
say " ! $rfile ($rmd5)";
push @diff, $rfile;
next;
}
- if($DEBUG) {
+ if ($DEBUG) {
say " $rfile";
}
}
# file that should have been in tar
@less = grep { $done{$_} == 0 } keys %done;
- for(@less) {
+ for (@less) {
say " - $_";
}
my %h;
- for(@$files) {
+ for (@$files) {
$h{$_->tarpath} = $_;
$done{$_->tarpath} = 0;
}
my $total = 0;
my $i = Archive::Tar->iter($tar, 1, {md5 => 1});
- while(my $f = $i->()) {
- if($f->has_content) {
+ while (my $f = $i->()) {
+ if ($f->has_content) {
$total++;
my $p = $f->full_path;
# file that shouldn't be there
- if(!exists $done{$p}) {
+ if (!exists $done{$p}) {
push @more, $p;
say " + $p";
next;
}
# same file multiple times
- if($done{$p} > 0) {
+ if ($done{$p} > 0) {
$done{$p}++;
push @more, $p;
printf " +%3d %s\n", $done{$p}, $p;
# different file
my $md5 = $f->data;
- if($^V lt v5.16) {
+ if ($^V lt v5.16) {
$md5 = md5_hex($md5);
}
- if($md5 ne $h{$p}->md5) {
+ if ($md5 ne $h{$p}->md5) {
say " ! $p ($md5)";
push @diff, $p;
next;
}
- if($DEBUG) {
+ if ($DEBUG) {
say " $p";
}
}
# file that should have been in tar
@less = grep { $done{$_} == 0 } keys %done;
- for(@less) {
+ for (@less) {
say " - $_";
}
quotemeta($fullpath),
join(' ', map {quotemeta} (@SMBARGS, @args)));
- if($DEBUG) {
+ if ($DEBUG) {
say color('bold yellow'),$cmd =~ s{\\([./+-])}{$1}gr,color('reset');
}
printf STDERR "child exited with value %d (%s)\n", ($err >> 8), $cmd;
}
- if($DEBUG) {
+ if ($DEBUG) {
say $out;
}
- if($err) {
+ if ($err) {
say "ERROR";
say $out;
exit 1;
=cut
sub random {
my ($min, $max) = @_;
- ($min, $max) = ($max, $min) if($min > $max);
+ ($min, $max) = ($max, $min) if ($min > $max);
$min + int(rand($max - $min));
}
$dir = '' if $dir eq './';
my $loc;
- if($abs) {
+ if ($abs) {
$loc = cleanpath($main::LOCALPATH.'/'.$dir);
} else {
$dir = cleanpath($main::DIR.'/'.$dir);
my $md5;
- if(defined $data) {
+ if (defined $data) {
open my $f, '>', $path or die "can't write in $path: $!";
print $f $data;
close $f;
=cut
sub localpath {
my $s = shift;
- if($s->{remote}) {
+ if ($s->{remote}) {
return cleanpath($main::LOCALPATH.'/'.$s->remotepath);
}
else {
$s->{attr} = {qw/r 0 s 0 h 0 a 0 d 0 n 0/};
- for(@flags) {
+ for (@flags) {
$s->{attr}{lc($_)} = 1;
}
my $file = $s->{name};
my @args;
- if($s->remotedir) {
+ if ($s->remotedir) {
push @args, '-D', $s->remotedir;
}
main::smb_client(@args, '-c', qq{setmode "$file" -rsha});
- if(@flags && $flags[0] !~ /n/i) {
+ if (@flags && $flags[0] !~ /n/i) {
main::smb_client(@args, '-c', qq{setmode "$file" +}.join('', @flags));
}
}
=cut
sub attr_any {
my ($s, @flags) = @_;
- for(@flags) {
+ for (@flags) {
return 1 if $s->{attr}{$_};
}
0;
=cut
sub attr {
my ($s, @flags) = @_;
- for(@flags) {
+ for (@flags) {
return 0 if !$s->{attr}{$_};
}
1;
sub md5 {
my $s = shift;
- if(!$s->{md5}) {
+ if (!$s->{md5}) {
open my $h, '<', $s->localpath() or die "can't read ".$s->localpath.": $!";
binmode $h;
$s->{md5} = Digest::MD5->new->addfile($h)->hexdigest;
sub DESTROY {
my $s = shift;
- if($s->{delete_on_destruction} && -f $s->localpath) {
- if($main::DEBUG) {
+ if ($s->{delete_on_destruction} && -f $s->localpath) {
+ if ($main::DEBUG) {
say "DESTROY ".$s->localpath;
}
unlink $s->localpath;
my @res;
for (@_) {
- if($_->{attr}{d}) {
+ if ($_->{attr}{d}) {
push @res, walk($fun, @{$_->{content}});
} else {
push @res, $fun->($_);
my @files;
my $out = main::smb_client('-D', $path, '-c', 'ls');
- for(split /\n/, $out) {
+ for (split /\n/, $out) {
next if !/^ (.+?)\s+([AHSRDN]*)\s+(\d+)\s+(.+)/o;
my ($fn, $attr, $size, $date) = ($1, $2, $3, $4);
next if $fn =~ /^\.{1,2}$/;
my ($d) = @_;
my @files;
- if(!defined $d) {
+ if (!defined $d) {
@files = list();
- } elsif(blessed $d) {
+ } elsif (blessed $d) {
@files = list($d->remotepath);
} else {
@files = list($d);
}
for my $f (@files) {
- if($f->{attr}{d}) {
+ if ($f->{attr}{d}) {
$f->{content} = [tree($f)];
}
}
my $size = main::random(512, 1024);
open my $out, '>', $fn or die "can't open $fn: $!\n";
binmode $out;
- for(1..$size) {
+ for (1..$size) {
$buf .= pack('C', main::random(0, 256));
}
print $out $buf;