File::R...:FileIO(3)
๐ NAME ๐
Okay so this whole page is the manual for File::RsyncP::FileIO (you'll see it filed under File::R...:FileIO(3) in the User Contributed Perl Documentation, no cap) โ it's the Perl Rsync client file system IO module. Bestie, it's giving "the plumbing behind the magic." Let's get into it. โจ
๐ฆ SYNOPSIS ๐ฆ
use File::RsyncP::FileIO;
my $rs = File::RsyncP->new({
logLevel => 1,
rsyncCmd => ["/bin/rsh", $host, "-l", $user, "/bin/rsync"],
rsyncArgs => [qw(
--numeric-ids
--perms
--owner
--group
--devices
--links
--ignore-times
--block-size=700
--relative
--recursive
-v
)],
logHandler => sub {
my($str) = @_;
print MyHandler "log: $str\n";
};
fio => File::RsyncP::FileIO->new({
logLevel => 1,
});
});
๐ DESCRIPTION ๐
File::RsyncP::FileIO is where all the file system access functions that File::RsyncP needs actually live. Why is it its own module? Because the vibes demanded it: this way the whole thing can be subclassed or swapped out for different code when your app is doing rsync over something that isn't a file system โ databases, for instance. Very demure, very modular. ๐
So here's the full roster of what File::RsyncP::FileIO gives you. ๐ซถ
๐งฐ Setup and utility functions ๐งฐ
new({ options... })โ makes you a brand newFile::RsyncP::FileIOobject. There's exactly one argument, and it's a hashref of options, which are:blockSizeโ defaults to700. You can totally change it later with theblockSizefunction. โจlogLevelโ defaults to0. This one controls how chatty the FileIO operations get. ๐digestโ defaults toFile::RsyncP::Digest->new. You literally never need to override this, bestie. Leave it. ๐checksumSeedโ the checksum seed used in digest calculations, defaulting to0. So here's the tea: the server-side Rsync generates a checksum seed and sends it over to the client. Which means this value usually gets set later, after the checksum seed arrives from the remote rsync, using thechecksumSeedfunction. ๐ฑlogHandlerโ a subroutine reference to a function that handles all the log messages. The default is a sub that just prints the messages toSTDERR. ๐ข
blockSize($value)โ sets the block size to this new value, for when you didn't already set it through theblockSizeoption innew(). ๐งchecksumSeed($seed)โ sets the checksum seed used in digest calculations to the new value. Usually you don't know this value yet whennew()is called, so yeah, you'll be setting it later through this function. Timing is everything. โฐlogHandlerSetโ sets the log handler callback function. Normally you'd pass this in vianew(), but it can be changed later with this function if you're feeling spontaneous. ๐dirs($localDir, $remoteDir)โ tells it the local directory and the remote directory. Two dirs, one function. ๐๏ธlog(@msg)โ saves one (or more) messages for logging purposes. ๐statsGetโ returns an optional hashref of statistics that the FileIO object compiled. Those values get passed opaquely up toFile::RsyncP. Very mysterious, very opaque. ๐ซfinish($isChild)โ does whatever finish-up processing is needed. The$isChildargument is true when this is the child process โ and remember, bestie, the receiving side runs two processes: the child receives the file deltas, while the parent generates the block digests. ๐ฏ
๐งฎ Checksum computation functions ๐งฎ
csumStart($f, $needMD4)โ gets ready to generate block checksums for the given file. The argument is a hashref, typically the one returned byFile::RsyncP::FileList->get. Typically this opens the underlying file and creates aFile::RsyncP::Digestobject. And if$needMD4is non-zero, thencsumEnd()will hand you back the file MD4 digest. ๐csumGet($num, $csumLen, $blockSize)โ returns$numblocks' worth of checksums, with the MD4 checksum length set to$csumLen(typically2or16), using a block size of$blockSize. Typically it reads the file and callsFile::RsyncP::Digest->blockDigest. ๐csumEnd()โ finishes up the checksum calculation, and typically closes the underlying file. Heads up:csumStart,csumGet,csumEndare called in strict order, so they don't need to be reentrant (i.e. only one csum is happening at a time). And ifcsumStart()was called with$needMD4, thencsumEnd()returns the file MD4 digest. ๐
๐ File reading functions ๐
These get used for sending files โ and quick note, sending files currently does not implement deltas; it behaves as though --whole-file was specified. ๐๏ธ
readStart($f)โ gets ready to read the given file. The argument is a hashref, typically the one returned byFile::RsyncP::FileList->get. Typically this opens the underlying file. ๐read($num)โ reads$numbytes from the file. ๐ฅreadEnd()โ finishes up the read operation, and typically closes the underlying file. Same deal as the checksums:readStart,readGet,readEndare called in strict order, so no reentrancy needed (only one read at a time, periodt). ๐
๐๏ธ File operations ๐๏ธ
attribGet($f)โ returns the attributes for the given file as a hashref. The argument is a hashref, typically the one returned byFile::RsyncP::FileList->get. ๐attribSet($f, $placeHolder)โ sets the attributes for the given file. The argument is a hashref, typically the one returned byFile::RsyncP::FileList->get. If$placeHolderis true, then don't do anything at all. Returnsundefon success. โmakePath($f)โ creates the directory that$fspecifies. The argument is a hashref, typically the one returned byFile::RsyncP::FileList->get. Returnsundefon success. ๐makeSpecial($f)โ creates the special file that$fspecifies. The argument is a hashref, typically the one returned byFile::RsyncP::FileList->get. Returnsundefon success. โญunlink($remotePath)โ unlinks the file or directory matching that given remote path. โ๏ธignoreAttrOnFile($f)โ normally this should returnundef, which means "use the default setting ofignore-times." Otherwise, if this function returns zero or non-zero, whatever it returns overrides theignore-timessetting for this particular file. The argument is a hashref, typically the one returned byFile::RsyncP::FileList->get. Peep thedoPartialoption inFile::RsyncP->new()for more. ๐
๐ฅ File delta receiving functions ๐ฅ
These functions only get called when we're receiving files. They're called by the child process. ๐ถ
fileDeltaRxStart($f, $cnt, $size, $remainder)โ starts the receiving of file deltas for file$f, a hashref typically returned byFile::RsyncP::FileList->get. The remaining arguments are the number of blocks, the size of blocks, and the size of the last (partial) block as generated by the parent on the receiving side โ so careful, they are not the values of the new file on the sending side. Returnsundefon success. ๐fileDeltaRxNext($blk, $newData)โ called over and over as the file gets constructed. Exactly one of$blkand$newDatais defined. If$blkis defined, it's an integer saying which block of the original file should be written at this point. If$newDatais defined, it's literal data โ stuff that didn't match any blocks โ that should be written at this point. ๐งฉfileDeltaRxDone($md4)โ finishes processing the file deltas for this file.$md4is the MD4 digest of the sent file, and you should compare it against the MD4 digest of the reconstructed file. Returnsundefon success,1if the file's MD4 didn't agree (meaning it should be repeated for phase 2), and a negative value on error. ๐ค
๐ค File list sending function ๐ค
fileListSend($fileList, $outputFunc)โ generates the file list (by calling$fileList->encodefor every file to be sent) and calls the output function$outputFuncwith the output data, like this:
&$outputFunc($fileList->encodeData);
๐ AUTHOR ๐
File::RsyncP::FileList was written by Craig Barratt <cbarratt@users.sourceforge.net>, based on rsync 2.5.5. Respect. ๐ซก
Rsync was written by Andrew Tridgell <tridge@samba.org> and Paul Mackerras. It's available under a GPL license โ go look at <http://rsync.samba.org>. ๐
๐ LICENSE ๐
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ๐
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. โ ๏ธ
You should have received a copy of the GNU General Public License in the LICENSE file along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ๐ฌ
๐ SEE ALSO ๐
- See <http://perlrsync.sourceforge.net> for File::RsyncP's SourceForge home page. ๐
- See
File::RsyncP,File::RsyncP::Digest, andFile::RsyncP::FileList. ๐ - Also peep BackupPC's
lib/BackupPC/Xfer/RsyncFileIO.pmfor an example of another implementation ofFile::RsyncP::FileIOโ and honestly, it's one that's more tested than the defaultFile::RsyncP::FileIO.pm. ๐ฅ
That's the whole page, bestie, no skips. โจ Signing off from perl v5.42.0, dated 2025-07-25, filed under File::R...:FileIO(3) โ mwah, slay, go read your file lists. ๐
๐
๐ฆ where this page comes from
- fedora 43: perl-File-RsyncP 0.76-22.fc43 ยท GPL-2.0-only AND GPL-3.0-only AND ( GPL-1.0-or-later OR Artistic-1.0-Perl )
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms