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 new File::RsyncP::FileIO object. There's exactly one argument, and it's a hashref of options, which are:
    • blockSize โ€” defaults to 700. You can totally change it later with the blockSize function. โœจ
    • logLevel โ€” defaults to 0. This one controls how chatty the FileIO operations get. ๐Ÿ”‡
    • digest โ€” defaults to File::RsyncP::Digest->new. You literally never need to override this, bestie. Leave it. ๐Ÿ™ˆ
    • checksumSeed โ€” the checksum seed used in digest calculations, defaulting to 0. 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 the checksumSeed function. ๐ŸŒฑ
    • logHandler โ€” a subroutine reference to a function that handles all the log messages. The default is a sub that just prints the messages to STDERR. ๐Ÿ“ข
  • blockSize($value) โ€” sets the block size to this new value, for when you didn't already set it through the blockSize option in new(). ๐Ÿ”ง
  • checksumSeed($seed) โ€” sets the checksum seed used in digest calculations to the new value. Usually you don't know this value yet when new() 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 via new(), 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 to File::RsyncP. Very mysterious, very opaque. ๐Ÿ’ซ
  • finish($isChild) โ€” does whatever finish-up processing is needed. The $isChild argument 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 by File::RsyncP::FileList->get. Typically this opens the underlying file and creates a File::RsyncP::Digest object. And if $needMD4 is non-zero, then csumEnd() will hand you back the file MD4 digest. ๐Ÿ”
  • csumGet($num, $csumLen, $blockSize) โ€” returns $num blocks' worth of checksums, with the MD4 checksum length set to $csumLen (typically 2 or 16), using a block size of $blockSize. Typically it reads the file and calls File::RsyncP::Digest->blockDigest. ๐Ÿ“–
  • csumEnd() โ€” finishes up the checksum calculation, and typically closes the underlying file. Heads up: csumStart, csumGet, csumEnd are called in strict order, so they don't need to be reentrant (i.e. only one csum is happening at a time). And if csumStart() was called with $needMD4, then csumEnd() 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 by File::RsyncP::FileList->get. Typically this opens the underlying file. ๐Ÿ”“
  • read($num) โ€” reads $num bytes from the file. ๐Ÿ“ฅ
  • readEnd() โ€” finishes up the read operation, and typically closes the underlying file. Same deal as the checksums: readStart, readGet, readEnd are 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 by File::RsyncP::FileList->get. ๐Ÿ”
  • attribSet($f, $placeHolder) โ€” sets the attributes for the given file. The argument is a hashref, typically the one returned by File::RsyncP::FileList->get. If $placeHolder is true, then don't do anything at all. Returns undef on success. โœ…
  • makePath($f) โ€” creates the directory that $f specifies. The argument is a hashref, typically the one returned by File::RsyncP::FileList->get. Returns undef on success. ๐Ÿ“
  • makeSpecial($f) โ€” creates the special file that $f specifies. The argument is a hashref, typically the one returned by File::RsyncP::FileList->get. Returns undef on success. โญ
  • unlink($remotePath) โ€” unlinks the file or directory matching that given remote path. โœ‚๏ธ
  • ignoreAttrOnFile($f) โ€” normally this should return undef, which means "use the default setting of ignore-times." Otherwise, if this function returns zero or non-zero, whatever it returns overrides the ignore-times setting for this particular file. The argument is a hashref, typically the one returned by File::RsyncP::FileList->get. Peep the doPartial option in File::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 by File::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. Returns undef on success. ๐Ÿš€
  • fileDeltaRxNext($blk, $newData) โ€” called over and over as the file gets constructed. Exactly one of $blk and $newData is defined. If $blk is defined, it's an integer saying which block of the original file should be written at this point. If $newData is 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. $md4 is the MD4 digest of the sent file, and you should compare it against the MD4 digest of the reconstructed file. Returns undef on success, 1 if 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->encode for every file to be sent) and calls the output function $outputFunc with 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, and File::RsyncP::FileList. ๐Ÿ’œ
  • Also peep BackupPC's lib/BackupPC/Xfer/RsyncFileIO.pm for an example of another implementation of File::RsyncP::FileIO โ€” and honestly, it's one that's more tested than the default File::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