File-RsyncP
view release on metacpan or search on metacpan
lib/File/RsyncP/FileIO.pm view on Meta::CPAN
{
my($fio, $checksumSeed) = @_;
$fio->{checksumSeed} = $checksumSeed;
}
sub dirs
{
my($fio, $localDir, $remoteDir) = @_;
$fio->{localDir} = $localDir;
$fio->{remoteDir} = $remoteDir;
}
sub attribGet
{
my($fio, $f) = @_;
my $localName = $fio->localName($f->{name});
my @s = stat($localName);
return if ( !@s );
return {
mode => $s[2],
uid => $s[4],
gid => $s[5],
size => $s[7],
mtime => $s[9],
}
}
#
# Set the attributes for a file. Returns non-zero on error.
#
sub attribSet
{
my($fio, $f, $placeHolder) = @_;
my $ret;
#
# Ignore placeholder attribute sets: only do real ones.
#
return if ( $placeHolder );
my $lName = $fio->localName($f->{name});
my @s = stat($lName);
my $a = {
mode => $s[2],
uid => $s[4],
gid => $s[5],
size => $s[7],
atime => $s[8],
mtime => $s[9],
};
$f->{atime} = $f->{mtime} if ( !defined($f->{atime}) );
if ( ($f->{mode} & ~S_IFMT) != ($a->{mode} & ~S_IFMT)
&& !chmod($f->{mode} & ~S_IFMT, $lName) ) {
$fio->log(sprintf("Can't chmod(%s, 0%o)", $lName, $f->{mode}));
$ret = -1;
}
if ( ($f->{uid} != $a->{uid} || $f->{gid} != $a->{gid})
&& !chown($f->{uid}, $f->{gid}, $lName) ) {
$fio->log("Can't chown($f->{uid}, $f->{gid}, $lName)");
$ret = -1;
}
if ( ($f->{mtime} != $a->{mtime} || $f->{atime} != $a->{atime})
&& !utime($f->{atime}, $f->{mtime}, $lName) ) {
$fio->log("Can't mtime($f->{atime}, $f->{mtime}, $lName)");
$ret = -1;
}
return $ret;
}
sub statsGet
{
my($fio) = @_;
return {};
}
#
# Make a given directory. Returns non-zero on error.
#
sub makePath
{
my($fio, $f) = @_;
my $localDir = $fio->localName($f->{name});
return $fio->attribSet($f) if ( -d $localDir );
File::Path::mkpath($localDir, 0, $f->{mode});
return $fio->attribSet($f) if ( -d $localDir );
$fio->log("Can't create directory $localDir");
return -1;
}
#
# Make a special file. Returns non-zero on error.
#
sub makeSpecial
{
my($fio, $f) = @_;
my $localPath = $fio->localName($f->{name});
#
# TODO: check if the special file is the same, then do nothing.
# Should also create as a new unique name, then rename/unlink.
#
$fio->unlink($f->{name});
if ( ($f->{mode} & S_IFMT) == S_IFCHR ) {
my($major, $minor);
$major = $f->{rdev} >> 8;
$minor = $f->{rdev} & 0xff;
return system("mknod $localPath c $major $minor");
} elsif ( ($f->{mode} & S_IFMT) == S_IFBLK ) {
my($major, $minor);
$major = $f->{rdev} >> 8;
$minor = $f->{rdev} & 0xff;
return system("mknod $localPath b $major $minor");
} elsif ( ($f->{mode} & S_IFMT) == S_IFLNK ) {
if ( !symlink($f->{link}, $localPath) ) {
# error
( run in 1.093 second using v1.01-cache-2.11-cpan-71847e10f99 )