Acme-Tools
view release on metacpan or search on metacpan
close($WIFH);
$keep || unlink($file);
}
=head2 chall
Does chmod + utime + chown on one or more files.
Returns the number of files of which those operations was successful.
Mode, uid, gid, atime and mtime are set from the array ref in the first argument.
The first argument references an array which is exactly like an array returned from perls internal C<stat($filename)> -function.
Example:
my @stat=stat($filenameA);
chall( \@stat, $filenameB, $filenameC, ... ); # by stat-array
chall( $filenameA, $filenameB, $filenameC, ... ); # by file name
Copies the chmod, owner, group, access time and modify time from file A to file B and C.
See C<perldoc -f stat>, C<perldoc -f chmod>, C<perldoc -f chown>, C<perldoc -f utime>
=cut
sub chall {
my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks )
= ref($_[0]) ? @{shift()} : stat(shift());
my $successful=0;
for(@_){ chmod($mode,$_) && utime($atime,$mtime,$_) && chown($uid,$gid,$_) && $successful++ }
return $successful;
}
=head2 makedir
Input: One or two arguments.
Works like perls C<mkdir()> except that C<makedir()> will create nesessary parent directories if they dont exists.
First input argument: A directory name (absolute, starting with C< / > or relative).
=head3 2bz2
=head3 2gz
The commands C<2xz>, C<2bz2> and C<2gz> are just synonyms for C<z2z> with an implicitly added option C<-t xz>, C<-t xz> or C<-t gz> accordingly.
z2z [-p -k -v -o -1 -2 -3 -4 -5 -6 -7 -8 -9 ] files
Converts (recompresses) files from one compression type to another. For instance from .gz to .bz2
Keeps uid, gid, mode (chmod) and mtime.
-p Show a progress meter using the pv program if installed
-k Keeps original file
-v Verbose, shows info on degree of compression and file
number if more than one file is being converted
-o Overwrites existing result file, otherwise stop with error msg
-1 .. -9 Degree of compression, -1 fastest .. -9 best
-e With -t xz (or 2xz) passes -e to xz (-9e = extreme compression)
-L rate With -p. Slow down, ex: -L 200K means 200 kilobytes per second
t/02_general.t view on Meta::CPAN
open my $fh2,">",$f2 or die$!;
close($fh1);close($fh2); #sleep_fp(0.5);
chmod(0457,$f1);#chmod(02457,$f1);
my $chown=chown(666,777,$f1);# or warn " -- Not checking chown, ok if not root\n";
utime(1e9,1.1e9,$f1);
my @stat=stat($f1);
my $chall_ant=chall(\@stat,$f2);
ok(!$chown || $chall_ant==1, "chall returned $chall_ant");
for(($f1,$f2)){
print "$_\n";
my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks ) = stat($_);
ok($mode%010000 == 0457, sprintf("mode=%05o",$mode));
ok(!$chown || $uid == 666, "uid=$uid");
ok(!$chown || $gid == 777, "gid=$gid");
ok($atime==1e9, "atime=$atime");
ok($mtime==1.1e9, "mtime=$mtime");
}
chmod(0777,$f1,$f2) and unlink($f1, $f2);
}
else {ok(1) for 1..11} # not linux
#--writefile, readfile
if($^O eq 'linux' and -w$tmp){
my $fn="$tmp/tmptestfile$$";
( run in 0.975 second using v1.01-cache-2.11-cpan-5735350b133 )