File-Rsync-0.43/0000755000076500007650000000000011242552335012717 5ustar leakinleakinFile-Rsync-0.43/Changelog0000644000076500007650000005403611242552311014533 0ustar leakinleakinTue Aug 18 10:56:10 CDT 2009 ( leakin at dfw dot nostrum dot com ) * version 0.43: Gavin Carr ( gavin at openfusion dot com dot au ) sent a patch to make include-from and exclude-from allow multiple arguments. This oversight was a misunderstanding on my part as to how these actually work. Many thanks to Gavin for correcting my preception in the form of a very helpful patch. also added support for new options in 2.6.7 removed 1 second sleep based on Petya Kohts testing ( kohts at yandex-team dot ru ) as this is un-needed paranoia added test to check for rsync binary in configured location Fri Jun 24 21:11:04 CDT 2005 ( leakin at dfw dot nostrum dot com ) * version 0.42: added Scalar::Util as a required module since it was not part of core before perl 5.8 (sorry). Also changed build-name for the config file so it will not clobber perl's Config.pm for odd @INC orders. Thanks again to Simon Myers (Smylers at stripey dot com ) for pointing out the potential problem. Tue May 24 11:28:43 CDT 2005 ( leakin at dfw dot nostrum dot com ) * version 0.41: fixed 'use Scalar::Util' again (hopefully correct this time). Trying to do too many things at once, and need work on tests to catch my bonehead mistakes. Improved test.pl coming soon. Mon May 23 16:51:42 CDT 2005 ( leakin at dfw dot nostrum dot com ) * version 0.40: I missed one critical line in the patch from Smylers and broke more than I fixed. This update includes the 'use' statement. Sun May 22 17:13:16 CDT 2005 ( leakin at dfw dot nostrum dot com ) * version 0.39: Simon Myers ( Smylers at stripey dot com ) sent a patch to allow Path::Class objects as source paths. The previous error checking only allowed source to be a string or an array. This update bypasses the sanity-check if the source is a blessed object and now assumes the programmer knows what they are doing and that the object can be read as a string. Added support for the only-write-batch option in rsync-2.6.5-pre1 Wed Mar 30 22:06:04 CST 2005 ( leakin at dfw dot nostrum dot com ) * version 0.38: Harald Flaucher ( Harald dot Flaucher at mondial dot de ) requested support for the --acls option, which is not part of rsync, but an included patch that some use. His request inspired the idea for the 'literal' option in the module to allow passing arbitrary literal arguments to rsync so other patches or even newer versions of rsync can be used. Also added support for the protocol option that was previously undocumented. Sat Mar 5 19:59:01 CST 2005 ( leakin at dfw dot nostrum dot com ) * version 0.37: added support for new options in 2.6.4-pre1: del, delete-before, delete-during, delay-updates, dirs, filter, fuzzy, itemize-changes, list-only, omit-dir-times, remove-sent-files, and max-size. See the rsync manpage for full details on these options. Fixed a type-o that kept partial-dir from being handled properly. Bill Uhl ( buhl at web-services dot net ) provided a patch to split out the creation of the rsync command from the exec function. The new call (getcmd) returns a reference to an array of the command to be executed. Bill is working on a graphical interface to rsync using this module and wants an alternate exec wrapper. This version includes a variation on his patch. Tue Jan 18 17:05:00 CST 2005 ( leakin at dfw dot nostrum dot com ) * versioon 0.36: fix for "uninitialized value" warning submitted thru rt.cpan.org. Thanks go to the anonymous Debian user (HTH). Wed Dec 8 18:33:45 CST 2004 ( leakin at dfw dot nostrum dot com ) * version 0.35: test 4 was failing due to bad pattern match in the test code. no functional changes (error message changed for 2.6.3). Thu Aug 12 20:45:43 CDT 2004 ( leakin at dfw dot nostrum dot com ) * version 0.34: added support for new options in 2.6.3: partial-dir, checksum-seed, keep-dirlinks, inplace, ipv4, and ipv6. Tue Jun 1 12:59:36 CDT 2004 ( leakin at dfw dot nostrum dot com ) * version 0.33: Fixed a type-o in parsing of quote-dst tag. Peter teStrake (peter dot testrake at tradingscreen dot com) pointed out that the exec method did not protect itself from a user-defined SIGCHLD handler and could miss the exit of rsync and report a false error. A local reset of the handler should protect it and still leave the handler in place for the rest of the user code. Sun Dec 21 03:18:26 CST 2003 ( leakin at dfw dot nostrum dot com ) * version 0.32: Added support for new option in 2.6.0: --from0, --no-relative, --no-implied-dirs, and --files-from. A new infun option has been added so a user-supplied function can print the list to --files-from=-. See the rsync man page and the pod doc for more info. Also fixed a bug underscores were not recognized as the hyphen equivalent for quote_dst, quote_src and path_to_rsync. An anonymous user submitted a fix where parens were needed due to precedence problems when srchost is defined. The fix is included in this release. Tue Jul 29 22:13:50 CDT 2003 ( leakin at dfw dot nostrum dot com ) * version 0.31: Bill Uhl ( buhl at web-services dot net ) sent a patch to add the missing ignore-existing option and make write-batch a scalar option (both were oversights on my part). He also suggested quoting the source paths. Since this could break intended actions, There are now 2 options to do this if desired. The quote-src and quote-dst flags will add double-quotes around each path in the source or the destination when set. This should help avoid with pathnames containing spaces. James CE Johnson sent a patch to add the no-stdin flag since calling the module under mod_perl was having problems. Bill also reported problems on win32 and I found strange behaviour myself during some tests, so I have backed-out the passing of stdin (from 0.27) entirely. Tue Jun 10 14:41:54 CDT 2003 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.30: Paul Egan sent a patch that does a much better job of cleaning up the select loop. I was still not taking full advantage of the features of IO::Select or IO::Handle. Thanks go to Paul for a much simplified loop, and hopefully an end to the hangs (at least those due to the perl code). Mon Jun 9 17:39:42 CDT 2003 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.29: Paul Egan had another suggestion I liked very much. I switched to using IO::Select rather than calling select directly. I've always hated the ugly vec code that must be added in order to use select. It clutters the program with lots of unrelated but essential cruft. The module keeps all that separate from what is going on in the rsync wrapper. Paul was still seeing a hang in certain cases, and Ronald J Kimball ( rjk at linguist dot thayer dot dartmouth dot edu ) was having similar problems. Both were seeing a hang on the eof tests, so I removed them (eof does not play well with sysread, but we need sysread to make sure we don't block). I have not been able to make it hang (at least not yet). Thu May 29 21:33:07 CDT 2003 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.28: Paul Egan ( paulegan at mail dot com ) found one of the cases where the module could block, and provided a patch to fix it. The cost is a going thru select again after each block is read, but he was able to prove it stops the hang. Paul also suggested an improvement on the sysread. I am now using the block size of the file descriptor (defaulting back to 1024 if that fails for some reason). Many thanks to Paul for not only finding a way to reproduce the hang, but also finding a fix. Sat Feb 1 23:03:55 CST 2003 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.27: got into too big a rush and forgot to test. The STDIN hack caused IPC::Open3 to spew, so I had to change it to glob to work properly. 0.26 was never released, but now I'm thinking seriously about breaking the link between the module version and RCS. I'll have to do this anyway if I move to Subversion for revision control, since it's versions are handled in a different manner. Mon Jan 13 11:25:42 CST 2003 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.26: Added link-dest option (new in 2.5.6pre1). I previously closed stdin of the forked rsync command since rsync didn't really use it. Now the include-from and exclude-from options may be set to '-' and rsync will read the list from stdin. I've attempted to pass STDIN directly to rsync in case someone wants to use this option. In my simple tests the code works, but I have not done extensive tests, and do not know if you can pass other data such as passwords (not a good idea in terms of security). This may also have other side effects since STDIN could be a tty in some instances and not in others (may cause the underlying rsh, ssh, or other transport to behave differently during testing versus cron or other unattended execution). If this becomes a problem for anyone I'll figure out some way to make it optional. Tue Jan 7 13:46:56 CST 2003 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.25: Tong Zhu ( tongzhu at thereinc dot com ) found an error where use of errfun and/or outfun exposed possible use of uninitialized variables (those used to break output into individual lines). Thanks for pointing out my error, and the useful 'diff' output making my coding error easy to track down and fix. Wed Dec 11 17:57:25 CST 2002 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.24: Heiko Jansen ( heiko_jansen at web dot de ) found an error in the exec function where I was accessing the errfun and outfun functions from the main object, and ignoring them if they were passed to 'exec'. Thanks for pointing out the error, hopefully this will work much better for you know. Wed Dec 4 22:38:14 CST 2002 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.23: I got 3 separate reports of hangs, but cannot reproduce the error (yet). Added a trap and more eof tests to hopefully catch and exit properly. Thu Mar 14 23:19:35 CST 2002 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.22: added options for rsync 2.5.4, no-blocking-io, no-detach, and no-whole-file. Thu Dec 20 13:52:33 CST 2001 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.21: added rsync+ options from 2.4.7pre4/2.5.0, read-batch and write-batch. Thanks to Jonathan Pelletier ( jonathan dot pelletier at matrox dot com ) for catching (and supply a fix for) an output message loss. This version contains a variation on his patch. Jonathan also suggested the new method 'lastcmd' to return the last 'rsync' command passed to the system for devugging and error messages. Fri Sep 7 15:18:58 CDT 2001 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.20: made changes to test.pl so failed tests would return non-zero exit and actually fail the tests. Also corrected several type-os in the POD documentation (thanks to Joe Smith ( Joe dot Smith at wcom dot com ) for pointing them out). Wed May 16 21:11:31 CDT 2001 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.19: discovered the new makefile was installing into the wrong path. It should follow the proper naming convention now. Thu May 10 22:28:28 CDT 2001 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.18: Many thanks to Andreas Koenig ( andreas dot koenig at dubravka dot kbx dot de ) for setting me straight on the architecture specific versus the arch-independent directory usage, and for explaining why this wasn't showing up in the by-module listings. The tar file now has a recognizable .pm file in it for proper CPAN distribution. There is also a File::Rsync::Config.pm in the arch-specific dir where the build process stores the path to the rsync executable. Mon May 7 01:07:44 CDT 2001 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.17: I decided it is better for the out and err methods to return any collected output regardless of whther or not an output function has been defined. This way you can process each line yourself and still print the entire output in bulk if desired. This also keeps me from having to work out what these methods should return if called when an output function has been defined. Thu Feb 15 21:25:23 CST 2001 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.16: James Mello ( kingjamm at colltech dot com ) submitted a patch to add a 'list' function, and educated me on the interesting aspect of calling rsync without a destination in order to obtain an 'ls -l' or 'ls -lr' (with -r or -a) style output. Rather than duplicating the exec function I made modifications to it and built a wrapper to get the list functionality. This has all kinds of possibilities. Many thanks to James for the great idea and the education on an option I had never explored. use File::Rsync;$rs=File::Rsync->new(srchost => 'localhost:'); print $rs->list; will list available modules on the local daemon. Tue Nov 28 10:22:50 CST 2000 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.15: After more thought and discussion with Boris we decided a second arg of either 'out' or 'err' should be passed to the functions so a single user-defined function could be used and it will be able to determine the source of the text in arg 1. Simple functions can ignore the second arg. The examples below would need to change to 'outfun => sub {print shift}' and 'errfun => sub {print shift}' to keep from printing the source string. (version 0.14 was not released to CPAN) Fri Nov 17 23:03:00 CST 2000 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.14: Per suggestion from Boris Goldowsky ( boris at range dot infoplease dot com ), added 'outfun' and 'errfun' options. If you supply a function (CODE) reference to these the stderr and stdout from rsync is passed to these functions one output line at a time and is not collected internally for post examination. Providing a function like 'outfun => sub {print @_}' will cause each line to be printed as they arrive. A function like 'outfun => sub {print "."}' will simply shows progress dots like cpio's -V option. Thanks to Boris for the suggestion. Sorry it took me so long to get it added. Sat Sep 16 23:32:59 CDT 2000 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.13: added suport for new flags blocking-io and ignore-errors, as well as scalars bwlimit, max-delete, and modify-window. I also rearranged the options hashes into a vertical sort similar to 'ls'. This makes additions a bit more difficult, but makes reading and verifying the options much easier (at least for me). Tue Feb 29 17:41:14 CST 2000 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.12: pervious version fixed blocking, but was not clean and caused the tests to fail in odd ways. This should be better. * also added code to treat underscore the same as hyphen in option keys similar to Tk. This allows the use of bareword keys in hashes without being mis-interpreted as subraction. Fri Feb 18 17:45:13 CST 2000 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.11: fixed a blocking problem in the exec function If one of the output pipes filled up it hung forever (oops). Mon Feb 7 14:05:37 CST 2000 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.10: removed comments about rsync not considering some things to be errors. This appears to be a bug in 2.3.2 on Linux. It has been submitted to the rsync team. On Solaris rsync properly returns a non-zero exit status if the source path does not exist. The bug was fixed in the CVS tree, and in the release 2.4.1. * added support for --backup-dir and --existing options (new in 2.4.1) * Since I've not heard from anyone about keeping the command-line style options, I've dropped them. The hash-style affords more flexibility anyway. I also removed some duplicate code in parseopts since I can now treat all args as a hash. * After some discussion on the rsync mailing list I was told about a method of passing multiple source arguments for a remote server. I've added a new hash key 'srchost' to be used in combination with the 'source' array to make it easier to use this capability. If the source host is remote, and you have multiple source paths, you can put the source hostname in 'srchost', and the paths in the 'source' array. The module will assemble them as a single argument to rsync. If 'srchost' is null then the 'source' array is passed to exec as seperate arguments. Wed Dec 1 21:55:44 CST 1999 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.09: removed bareword keys in hashes (5.00404 doesn't like my use of 'scalar' as a key) * version 0.08: changed test 5 in test.pl to account for different return status between Solaris and Linux. I'll need to look into why one detects the error and the other doesn't (rsync itself, not perl). Tue Nov 30 20:46:00 CST 1999 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.07: * removed global $pkgname, now uses 'my $pkgname=ref $self' instead. I also had to bless $self earlier in 'new' so defopts, and parseopts can use 'ref $self' to determine the package name. It was not too bright to hardcode the package name (vacations can have odd effects on the brain) * changed saveopts and parseopts to begin with underscore since they are for internal use only. Sun Nov 28 19:41:31 CST 1999 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.06: * added $pkgname for 'carp' messages to make it clearer where they came from. * added missing check for 'include' in exec method * other misc cleanup and clarification of code and documentation Sun Nov 28 02:47:34 CST 1999 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.05: major re-organization and re-writing of internal functions to add the ability to pass a hash reference for perl-style options handling. (Thanks to Greg Ward for the suggestion) This gives increased flexibility including the ability to turn off boolean flags, and to build your own include or exclude list as an array and pass a reference to the array to the module. The same can be done for source paths. * removed leading double-dashes from the option keys. It is easier to add them in the parser for command-line style than to remove them for perl-style hashes. * changed 'err' and 'out' methods to return an empty string or an empty list if no output was generated. If there was output they return it as an array or a reference to an array as before. This should make testing for the existance of output more efficient. Before you had to call them in a scalar context and dereference the return in order to check. Now you can use a simple truth test. Also added a note about conditions where rsync itself can return a true (0) exit but the programmer may consider it an error. In these situations you need to check stderr for error messages (such as 'no such file or directory'). See 'exec' method in the manpage. * removed newlines from carp messages so the 'at line ##' is on the same line as the rest of the error message (bad habit from die). * changed all return values except 'new' to zero instead of undef so -w won't complain about use of un-initialized values. If anyone has a good reason to put this back (like good/standard coding practices) let me know. * added test.pl script for 'make test'. Sun Nov 21 02:18:56 CST 1999 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.04: added missing 'next' that would cause a parsing error if -P was used. * Renamed module to File::Rsync (Thanks to Tim Bunce for the suggestion) It really fits better here than in Net::, but once I thought of it as a network-based program I had a mental block when considering other groups. Fri Nov 19 13:25:18 CST 1999 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.03: --address should be a scalar, not a flag (the rsync man page is unclear on this). Wed Nov 17 21:20:16 CST 1999 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.02: * wrote first draft of Makefile.PL and makepm.PL to wrap it all up as a real perl module. * added new options for rsync 2.3.2 (-P, --delete-after, and --address) -P is short for --partial and --progress. --address is only used in server mode. I don't know what good these are inside this module, but you should still be able to pass them if you want. --delete-after allows the user to delay any --delete actions until after all other files are synced. The default is to perform any deletes before in order help insure sufficient disk space is available. See the rsync (1) man page for more details. * remove any chance of clobbering $_ (mostly paranoia I hope) Tue Jun 15 15:27:20 CDT 1999 Lee Eakin ( leakin at dfw dot nostrum dot com ) * version 0.01: (initial) based on rsync 2.3.1 File-Rsync-0.43/MANIFEST0000644000076500007650000000013111122300237014030 0ustar leakinleakinChangelog config.in MANIFEST Makefile.PL README Rsync.pm TODO makepm.PL test.pl META.yml File-Rsync-0.43/META.yml0000644000076500007650000000102011242552335014161 0ustar leakinleakin--- #YAML:1.0 name: File-Rsync version: 0.43 abstract: Wrapper module for rsync(1) http://rsync.samba.org/ author: - Lee Eakin license: unknown distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 requires: Scalar::Util: 0 no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.48 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 File-Rsync-0.43/Makefile.PL0000644000076500007650000000155311122300237014662 0ustar leakinleakin# This -*- perl -*- script writes the Makefile for File-Rsync use 5.004; use ExtUtils::MakeMaker; use Config; $NAME = 'File::Rsync'; $DISTNAME = 'File-Rsync'; $VERSION_FROM = 'Rsync.pm'; $AUTHOR = 'Lee Eakin '; $ABSTRACT = 'Wrapper module for rsync(1) http://rsync.samba.org/'; WriteMakefile( VERSION_FROM => $VERSION_FROM, NAME => $NAME, DISTNAME => $DISTNAME, AUTHOR => $AUTHOR, ABSTRACT => $ABSTRACT, PREREQ_PM => { 'Scalar::Util' => 0 }, PL_FILES => { 'makepm.PL' => 'config.pm' }, PM => { 'Rsync.pm' => '$(INST_LIB)/File/Rsync.pm', 'config.pm' => '$(INST_ARCHLIB)/File/Rsync/Config.pm' }, dist => { COMPRESS => 'gzip', SUFFIX => 'gz' }, realclean => { FILES => 'config.pm' }, ); File-Rsync-0.43/README0000644000076500007650000000305011242552033013570 0ustar leakinleakinFile-Rsync - A wrapper module for rsync(1) http://rsync.samba.org/rsync/ ******************************************************************************* Copyright (C) 2000-2005 Lee Eakin. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. ******************************************************************************* Updated to support new options of rsync 2.6.7 This is a long overdue update that has been sitting in my queue. Another update is due as well that would change to orderd args based on discussions with Gavin Carr. I hope to have it ready soon along with any new option support since 2.6.7. Although I am the original author and maintainer, many of the bug fixes and improvements have come as either suggestions or patches from the perl community. The contributors names can be found near the end of the POD doc, and full credits can be found in the Changelog file. There have been many helpful people making this a much better module than I could ever write on my own. QUICK START GUIDE: Install rsync if you haven't already. Build/test/install File::Rsync perl Makefile.PL make make test make install Once installed you can use 'perldoc File::Rsync' to get the rest of the documentation. Or if you'd prefer to examine the docs before installation try 'perldoc -F Rsync.pm'. This module is an attempt to efficiently handle the possibly numerous arguments to the rsync command, and it's error conditions and messages. File-Rsync-0.43/Rsync.pm0000644000076500007650000007474611242550037014372 0ustar leakinleakin# -*- perl -*- # vim:ft=perl foldlevel=1 # __ # /\ \ From the mind of # / \ \ # / /\ \ \_____ Lee Eakin ( Leakin at dfw dot Nostrum dot com ) # / \ \ \______\ or ( Leakin at cpan dot org ) # / /\ \ \/____ / or ( Leakin at japh dot net ) # \ \ \ \____\/ / or ( Lee at Eakin dot Org ) # \ \ \/____ / Wrapper module for the rsync program # \ \____\/ / rsync can be found at http://rsync.samba.org/rsync/ # \/______/ package File::Rsync; require 5.004; # it might work with older versions of 5 but not tested use FileHandle; use IPC::Open3 qw(open3); use IO::Select; use POSIX ":sys_wait_h"; use Carp 'carp'; use File::Rsync::Config; use Scalar::Util qw(blessed); use strict; use vars qw($VERSION); $VERSION = '0.43'; =head1 NAME File::Rsync - perl module interface to rsync(1) F =head1 SYNOPSIS use File::Rsync; $obj = File::Rsync->new( { archive => 1, compress => 1, rsh => '/usr/local/bin/ssh', 'rsync-path' => '/usr/local/bin/rsync' } ); $obj->exec( { src => 'localdir', dest => 'rhost:remdir' } ) or warn "rsync failed\n"; =head1 DESCRIPTION Perl Convenience wrapper for the rsync(1) program. Written for I and updated for I but should perform properly with most recent versions. =over 4 =item File::Rsync::new $obj = I File::Rsync; or $obj = File::Rsync->I; or $obj = File::Rsync->new(@options); or $obj = File::Rsync->new(\%options); Create a I object. Any options passed at creation are stored in the object as defaults for all future I calls on that object. Options may be passed in the form of a hash and are the same as the long options in I with the leading double-dash removed. An additional option of B also exists which can be used to override the hardcoded path to the rsync binary that is defined when the module is installed, and B which causes the module methods to print some debugging information to STDERR. There are also 2 options to wrap the source and/or destination paths in double-quotes. They are B and B, and may be useful in protecting the paths from shell expansion (particularly useful for paths containing spaces). The B and B options take a function reference. The function is called once for each line of output from the I program with the output line passed in as the first argument, the second arg is either 'out' or 'err' depending on the source. This makes it possible to use the same function for both and still determine where the output came from. Options may also be passed as a reference to a hash. The B option needs an array reference as its value, since there cannot be duplicate keys in a hash. There is an equivalent B option. Only an B or B option should be used, not both. Use the '+ ' or '- ' prefix trick to put includes in an B array, or to put excludes in an B array (see I for details). Include/exclude options form an ordered list. The order must be retained for proper execution. There are also B and B keys. The key B is also accepted as an equivalent to B, and B or B may be used as equivalents to B. The B option may take a scalar or an array reference. If the source is the local system then multiple B paths are allowed. In this case an array reference should be used. There is also a method for passing multiple source paths to a remote system. This method may be triggered in this module by passing the remote hostname to the B key and passing an array reference to the B key. If the source host is being accessed via an Rsync server, the remote hostname should have a single trailing colon on the name. When rsync is called, the B value and the values in the B array will be joined with a colon resulting in the double-colon required for server access. The B key only takes a scalar since I only accepts a single destination path. Version 2.6.0 of I provides a new B option along with a few other supporting options (B, B, and B). To support this wonderful new option at the level it deserves, this module now has an additional parameter. If B is set to '-' (meaning read from stdin) you can define B to be a reference to a function that prints your file list to the default file handle. The output from the function is attached to stdin of the rsync call during exec. If B is defined it will be called regardless of the value of B, so it can provide any data expected on stdin, but keep in mind that stdin will not be attached to a tty so it is not very useful for sending passwords (see the I and I man pages for ways to handle authentication). The I man page has a more complete description of B. Also see L for ideas to use with B and B. The B option may also be used with the B or B settings, but this is generally more clumsy than using the B or B arrays. Version 2.6.3 of I provides new options B, B, B, B, B, and B. Version 2.6.4 of I provides new options B, B B, B, B, B, B, B, B, B, B, B, and B. Version 0.38 of this module also adds support for the B option that is not part of I unless the patch has been applied, but people do use it. It also includes a new B option that takes an array reference similar to B, B, and B. Any arguments in the array are passed as literal arguments to rsync, and are passed first. They should have the proper single or double hyphen prefixes and the elements should be split up the way you want them passed to exec. The purpose of this option is to allow the use of arbitrary options added by patches, and/or to allow the use of new options in rsync without needing an imediate update to the module in addtition to I itself. =back =cut sub new { my $class = shift; # seed the options hash, booleans, scalars, excludes, source, dest, data, # status, stderr/stdout storage for last exec my $self = { # the full path name to the rsync binary 'path-to-rsync' => $RsyncConfig{rsync_path}, # these are the boolean flags to rsync, all default off, including them # in the args list turns them on 'flag' => {qw( 8-bit-output 0 fuzzy 0 no-specials 0 acls 0 group 0 no-super 0 append 0 hard-links 0 no-times 0 archive 0 help 0 no-whole-file 0 backup 0 ignore-errors 0 numeric-ids 0 blocking-io 0 ignore-existing 0 omit-dir-times 0 checksum 0 ignore-non-existing 0 one-file-system 0 compress 0 ignore-times 0 whole-file 0 copy-dirlinks 0 inplace 0 owner 0 copy-links 0 ipv4 0 partial 0 copy-unsafe-links 0 ipv6 0 perms 0 cvs-exclude 0 keep-dirlinks 0 progress 0 daemon 0 links 0 prune-empty-dirs 0 del 0 list-only 0 recursive 0 delay-updates 0 no-blocking-io 0 relative 0 delete 0 no-detach 0 remove-sent-files 0 delete-after 0 no-devices 0 safe-links 0 delete-before 0 no-dirs 0 size-only 0 delete-during 0 no-groups 0 sparse 0 delete-excluded 0 no-implied-dirs 0 specials 0 devices 0 no-links 0 stats 0 dirs 0 no-owner 0 super 0 dry-run 0 no-partial 0 times 0 executability 0 no-perms 0 update 0 existing 0 no-progress 0 version 0 force 0 no-recursive 0 xattrs 0 from0 0 no-relative 0 )}, # these have simple scalar args we cannot easily check 'scalar' => {qw( address 0 log-format 0 protocol 0 backup-dir 0 max-delete 0 read-batch 0 block-size 0 max-size 0 rsh 0 bwlimit 0 min-size 0 rsync-path 0 checksum-seed 0 modify-window 0 sockopts 0 compress-level 0 only-write-batch 0 suffix 0 config 0 partial-dir 0 temp-dir 0 csum-length 0 password-file 0 timeout 0 files-from 0 port 0 write-batch 0 )}, # these are not flags but counters, each time they appear it raises the # count, so we keep track and pass them the same number of times 'counter' => {qw( human-readable 0 one-file-system 0 verbose 0 itemize-changes 0 quiet 0 )}, # these can be specified multiple times and are additive, the doc also # specifies that it is an ordered list so we must preserve that order 'chmod' => [], 'compare-dest' => [], 'copy-dest' => [], 'exclude' => [], 'exclude-from' => [], 'filter' => [], 'include' => [], 'include-from' => [], 'link-dest' => [], 'literal' => [], # hostname of source, used if 'source' is an array reference 'srchost' => '', # source host and/or path names 'source' => '', # destination host and/or path 'dest' => '', # return status from last exec 'status' => 0, 'realstatus' => 0, # last rsync command-line executed 'lastcmd' => undef, # whether or not to print debug statements 'debug' => 0, # double-quote source and/or destination paths 'quote-src' => 0, 'quote-dst' => 0, # stderr from last exec in array format (messages from remote rsync proc) 'err' => 0, 'errfun' => undef, # stdout from last exec in array format (messages from local rsync proc) 'out' => 0, 'outfun' => undef, # function to prvide --*-from=- data via pipe 'infun' => undef, # this flag changes error checking in 'exec' when called by 'list' 'list' => 0, }; bless $self, $class; # bless it first so defopts can find out the class if (@_) { &defopts($self,@_) or return; } return $self; } =over 4 =item File::Rsync::defopts $obj->defopts(@options); or $obj->defopts(\%options); Set default options for future exec calls for the object. See I for a complete list of valid options. This is really the internal method that I calls but you can use it too. The B and B options to rsync are actually counters. When assigning the perl hash-style options you may specify the counter value directly and the module will pass the proper number of options to rsync. =back =cut sub defopts { # this method has now been split into 2 sub methods (parse and save) # _saveopts and _parseopts should only be used via defopts or exec my $self = shift; &_saveopts($self,&_parseopts($self,@_)); } sub _parseopts { # this method checks and converts it's args into a reference to a hash # of valid options and returns it to the caller my $self = shift; my $pkgname = ref $self; my @opts = @_; my $opt; my %OPT = (); # this is the hash we will return a ref to # make sure we are passed the proper number of args if (@opts == 1) { $opt = shift; if (my $reftype = ref $opt) { unless ($reftype eq 'HASH') { carp "$pkgname: invalid reference type ($reftype) in options"; return; } } else { carp "$pkgname: invalid option ($opt)"; return; } } elsif (@opts % 2) { carp "$pkgname: invalid number of options passed (must be key/value pairs)"; return; } else { $opt = {@opts}; } # now process the options given, we handle debug first since hashes do not # have a specific order, and it would not be set first even if we sorted if (exists $opt->{'debug'}) { $OPT{'debug'} = $opt->{'debug'}; print(STDERR "setting debug flag\n") if $OPT{'debug'}; } foreach my $hashopt (keys %$opt) { my $savopt = $hashopt; $savopt =~ tr/_/-/; next if $hashopt eq 'debug'; # we did this one first (above) print STDERR "processing option: $hashopt\n" if $OPT{'debug'} or $self->{'debug'}; if (exists $self->{'flag'}{$savopt} or exists $self->{'scalar'}{$savopt} or exists $self->{'counter'}{$savopt}) { $OPT{$savopt} = $opt->{$hashopt}; } else { my $tag = ''; if ( $hashopt eq 'chmod' or $hashopt eq 'compare-dest' or $hashopt eq 'copy-dest' or $hashopt eq 'exclude' or $hashopt eq 'exclude-from' or $hashopt eq 'filter' or $hashopt eq 'include' or $hashopt eq 'include-from' or $hashopt eq 'link-dest' or $hashopt eq 'literal') { $tag = $hashopt; } elsif ($hashopt eq 'source' or $hashopt eq 'src') { $tag = 'source'; } if ($tag) { if (my $reftype = ref $opt->{$hashopt}) { if ($reftype eq 'ARRAY') { $OPT{$tag} = $opt->{$hashopt}; } elsif ($tag eq 'source' && blessed $opt->{$hashopt}) { $OPT{$tag} = [ $opt->{$hashopt} ]; } else { carp "$pkgname: invalid reference type for $hashopt option"; return; } } elsif ($tag eq 'source') { $OPT{$tag} = [ $opt->{$hashopt} ]; } else { carp "$pkgname: $hashopt is not a reference"; return; } } elsif ($hashopt eq 'dest' or $hashopt eq 'destination' or $hashopt eq 'dst') { $OPT{'dest'} = $opt->{$hashopt}; } elsif ($savopt eq 'path-to-rsync' or $savopt eq 'srchost' or $savopt eq 'quote-dst' or $savopt eq 'quote-src') { $OPT{$savopt} = $opt->{$hashopt}; } elsif ($hashopt eq 'outfun' or $hashopt eq 'errfun' or $hashopt eq 'infun') { if (ref $opt->{$hashopt} eq 'CODE') { $OPT{$hashopt} = $opt->{$hashopt}; } else { carp "$pkgname: $hashopt option is not a function reference"; return; } } else { carp "$pkgname: $hashopt - unknown option"; return; } } } return \%OPT; } sub _saveopts { # this method saves the data from the hash passed to it in the object's # hash my $self = shift; my $pkgname = ref $self; my $opts = shift; return unless ref $opts eq 'HASH'; foreach my $opt (keys %$opts) { if (exists $self->{'flag'}{$opt}) { $self->{'flag'}{$opt} = $opts->{$opt}; } elsif (exists $self->{'scalar'}{$opt}) { $self->{'scalar'}{$opt} = $opts->{$opt}; } elsif (exists $self->{'counter'}{$opt}) { $self->{'counter'}{$opt} = $opts->{$opt}; } elsif ($opt eq 'chmod' or $opt eq 'compare-dest' or $opt eq 'copy-dest' or $opt eq 'link-dest' or $opt eq 'exclude' or $opt eq 'exclude-from' or $opt eq 'include' or $opt eq 'include-from' or $opt eq 'filter' or $opt eq 'source' or $opt eq 'dest' or $opt eq 'debug' or $opt eq 'outfun' or $opt eq 'errfun' or $opt eq 'infun' or $opt eq 'path-to-rsync' or $opt eq 'srchost' or $opt eq 'quote-dst' or $opt eq 'quote-src' or $opt eq 'literal') { $self->{$opt} = $opts->{$opt}; } else { carp "$pkgname: unknown option: $opt"; return; } } return 1; } =over 4 =item File::Rsync::getcmd my $cmd = $obj->getcmd(@options); or my $cmd = $obj->getcmd(\%options); or my ($cmd, $infun, $outfun, $errfun, $debug) = $obj->getcmd(\%options); I returns a reference to an array containing the real rsync command that would be called if the exec function were called. The last example above includes a reference to the optional stdin function, stdout function, stderr function, and the debug setting. This is the form used by the I method to get the extra parameters it needs to do its job. The function is exposed to allow a user-defined exec function to be used, or for debugging purposes. =back =cut sub getcmd { my $self = shift; my $pkgname = ref $self; my $merged = $self; my $list = $self->{list}; $self->{list} = 0 if $self->{list}; if (@_) { # If args are passed to exec then we have to merge the saved # (default) options with those passed, for any conflicts those passed # directly to exec take precidence my $execopts = &_parseopts($self,@_); return unless ref $execopts eq 'HASH'; my %runopts = (); # first copy the default info from $self foreach my $type (qw(flag scalar counter)) { foreach my $opt (keys %{$self->{$type}}) { $runopts{$type}{$opt} = $self->{$type}{$opt}; } } foreach my $opt (qw(path-to-rsync chmod compare-dest copy-dest exclude exclude-from filter include include-from link-dest source srchost debug dest outfun errfun infun quote-dst quote-src literal)) { $runopts{$opt} = $self->{$opt}; } # now allow any args passed directly to exec to override foreach my $opt (keys %$execopts) { if (exists $runopts{'flag'}{$opt}) { $runopts{'flag'}{$opt} = $execopts->{$opt}; } elsif (exists $runopts{'scalar'}{$opt}) { $runopts{'scalar'}{$opt} = $execopts->{$opt}; } elsif (exists $runopts{'counter'}{$opt}) { $runopts{'counter'}{$opt} = $execopts->{$opt}; } elsif ($opt eq 'chmod' or $opt eq 'compare-dest' or $opt eq 'copy-dest' or $opt eq 'link-dest' or $opt eq 'exclude' or $opt eq 'exclude-from' or $opt eq 'include' or $opt eq 'include-from' or $opt eq 'filter' or $opt eq 'source' or $opt eq 'dest' or $opt eq 'debug' or $opt eq 'outfun' or $opt eq 'errfun' or $opt eq 'infun' or $opt eq 'path-to-rsync' or $opt eq 'srchost' or $opt eq 'quote-dst' or $opt eq 'quote-src' or $opt eq 'literal') { $runopts{$opt} = $execopts->{$opt}; } else { carp "$pkgname: unknown option: $opt"; return; } } $merged = \%runopts; } my @cmd = ($merged->{'path-to-rsync'}); # put any literal options first push @cmd,@{$merged->{'literal'}} if @{$merged->{'literal'}}; foreach my $opt (sort keys %{$merged->{'flag'}}) { push @cmd,"--$opt" if $merged->{'flag'}{$opt}; } foreach my $opt (sort keys %{$merged->{'scalar'}}) { push @cmd,"--$opt=$merged->{'scalar'}{$opt}" if $merged->{'scalar'}{$opt}; } foreach my $opt (sort keys %{$merged->{'counter'}}) { for (my $i = 0;$i<$merged->{'counter'}{$opt};$i++) { push @cmd,"--$opt"; } } if ((@{$merged->{'exclude'}} != 0) + (@{$merged->{'include'}} != 0) + (@{$merged->{'filter'}} != 0) > 1) { carp "$pkgname: 'exclude' and/or 'include' and/or 'filter' options specified, only one allowed"; return; } foreach my $opt (@{$merged->{'chmod'}}) { push @cmd,"--chmod=$opt"; } foreach my $opt (@{$merged->{'compare-dest'}}) { push @cmd,"--compare-dest=$opt"; } foreach my $opt (@{$merged->{'copy-dest'}}) { push @cmd,"--copy-dest=$opt"; } foreach my $opt (@{$merged->{'exclude'}}) { push @cmd,"--exclude=$opt"; } foreach my $opt (@{$merged->{'exclude-from'}}) { push @cmd,"--exclude-from=$opt"; } foreach my $opt (@{$merged->{'filter'}}) { push @cmd,"--filter=$opt"; } foreach my $opt (@{$merged->{'include'}}) { push @cmd,"--include=$opt"; } foreach my $opt (@{$merged->{'include-from'}}) { push @cmd,"--include-from=$opt"; } foreach my $opt (@{$merged->{'link-dest'}}) { push @cmd,"--link-dest=$opt"; } if ($merged->{'source'}) { if ($merged->{'srchost'}) { push @cmd, "$merged->{'srchost'}:" . join ' ', $merged->{'quote-src'} ? map { "\"$_\"" } @{$merged->{'source'}} : @{$merged->{'source'}}; } else { push @cmd, $merged->{'quote-src'} ? map { "\"$_\"" } @{$merged->{'source'}} : @{$merged->{'source'}}; } } elsif ($merged->{'srchost'} and $list) { push @cmd, "$merged->{'srchost'}:"; } else { if ($list) { carp "$pkgname: no 'source' specified"; return; } elsif ($merged->{'dest'}) { carp "$pkgname: option 'dest' specified without 'source' option"; return; } else { carp "$pkgname: no source or destination specified"; return; } } unless ($list) { if ($merged->{'dest'}) { push @cmd, $merged->{'quote-dst'} ? "\"$merged->{'dest'}\"" : $merged->{'dest'}; } else { carp "$pkgname: option 'source' specified without 'dest' option"; return; } } return(wantarray ? (\@cmd, $merged->{'infun'}, $merged->{'outfun'}, $merged->{'errfun'}, $merged->{'debug'}) : \@cmd); } =over 4 =item File::Rsync::exec $obj->exec(@options) or warn "rsync failed\n"; or $obj->exec(\%options) or warn "rsync failed\n"; This is the method that does the real work. Any options passed to this routine are appended to any pre-set options and are not saved. They effect the current execution of I only. In the case of conflicts, the options passed directly to I take precedence. It returns B<1> if the return status was zero (or true), if the I return status was non-zero it returns B<0> and stores the return status. You can examine the return status from I and any output to stdout and stderr with the methods listed below. =back =cut sub exec { my $self = shift; my ($cmd, $infun, $outfun, $errfun, $debug) = $self->getcmd(@_); return unless $cmd; print STDERR "exec: @$cmd\n" if $debug; my $out = FileHandle->new; my $err = FileHandle->new; $err->autoflush(1); $out->autoflush(1); local $SIG{CHLD}='DEFAULT'; my $pid; { my $in = FileHandle->new; $in->autoflush(1); $pid = eval{ open3 $in,$out,$err,@$cmd }; $self->{lastcmd} = $cmd; if ($@) { $self->{'realstatus'} = 0; $self->{'status'} = 255; $self->{'err'} = [$@,"Execution of rsync failed.\n"]; return 0; } if ($infun) { select((select($in),&{$infun})[0]); } $in->close; } my $odata = my $edata = ''; my $stream = { $out->fileno => { name => 'out', data => \$odata, buffer_tail => '', block_size => ($out->stat)[11] || 1024, handler => $outfun }, $err->fileno => { name => 'err', data => \$edata, buffer_tail => '', block_size => ($err->stat)[11] || 1024, handler => $errfun } }; my $select = IO::Select->new; $select->add($out,$err); while ($out->opened or $err->opened) { foreach my $fd ( $select->can_read(1) ) { my $str = $stream->{$fd->fileno}; warn("stream not found") unless $str; my $buffer; if ( $fd->sysread($buffer, $str->{block_size}) ) { ${$str->{data}} .= $buffer; if ( $str->{handler} ) { my $tail = ''; $tail = $1 if $buffer =~ s/([^\n]+)\z//s; foreach my $line ( split /^/m, $str->{buffer_tail}.$buffer ) { &{$str->{handler}}($line, $str->{name}); } $str->{buffer_tail} = $tail; } } else { $select->remove($fd); $fd->close; } } } $self->{'out'} = $odata ? [ split /^/m,$odata ] : ''; $self->{'err'} = $edata ? [ split /^/m,$edata ] : ''; $out->close; $err->close; waitpid $pid,0; $self->{'realstatus'} = $?; $self->{'status'} = $?>>8; return($self->{'status'} ? 0 : 1); } =over 4 =item File::Rsync::list $out = $obj->list(@options); or $out = $obj->list(\%options); or @out = $obj->list(\%options); This is a wrapper for I called without a destination to get a listing. It returns the output of stdout like the I function below. When no destination is given rsync returns the equivalent of 'ls -l' or 'ls -lr' modified by any include/exclude/filter parameters you specify. This is useful for manual comparison without actual changes to the destination or for comparing against another listing taken at a different point in time. (As of rsync version 2.6.4-pre1 this can also be accomplished with the 'list-only' option regardless of whether a destination is given.) =back =cut sub list { my $self = shift; $self->{list}++; $self->exec(@_); if ($self->{'out'}) { return(wantarray ? @{$self->{'out'}} : $self->{'out'}); } else { return; } } =over 4 =item File::Rsync::status $rval = $obj->I; Returns the status from last I call right shifted 8 bits. =back =cut sub status { my $self = shift; return $self->{'status'}; } =over 4 =item File::Rsync::realstatus $rval = $obj->I; Returns the real status from last I call (not right shifted). =back =cut sub realstatus { my $self = shift; return $self->{'realstatus'}; } =over 4 =item File::Rsync::err $aref = $obj->I; In a scalar context this method will return a reference to an array containing all output to stderr from the last I call, or zero (false) if there was no output. In an array context it will return an array of all output to stderr or an empty list. The scalar context can be used to efficiently test for the existance of output. I sends all messages from the remote I process and any error messages to stderr. This method's purpose is to make it easier for you to parse that output for appropriate information. =back =cut sub err { my $self = shift; if ($self->{'err'}) { return(wantarray ? @{$self->{'err'}} : $self->{'err'}); } else { return; } } =over 4 =item File::Rsync::out $aref = $obj->I; Similar to the I method, in a scalar context it returns a reference to an array containing all output to stdout from the last I call, or zero (false) if there was no output. In an array context it returns an array of all output to stdout or an empty list. I sends all informational messages (B option) from the local I process to stdout. =back =cut sub out { my $self = shift; if ($self->{'out'}) { return(wantarray ? @{$self->{'out'}} : $self->{'out'}); } else { return; } } =over 4 =item File::Rsync::lastcmd $aref = $obj->I; Returns the actual system command used by the last I call, or '' before any calls to I for the object. This can be useful in the case of an error condition to give a more informative message or for debugging purposes. In an array context it return an array of args as passed to the system, in a scalar context it returns a space-seperated string. See I for access to the command before execution. =back =cut sub lastcmd { my $self = shift; if ($self->{lastcmd}) { return wantarray ? @{$self->{lastcmd}} : join ' ',@{$self->{lastcmd}}; } else { return; } } =head1 Author Lee Eakin Eleakin@dfw.nostrum.comE =head1 Credits The following people have contributed ideas, bug fixes, code or helped out by reporting or tracking down bugs in order to improve this module since it's initial release. See the Changelog for details: Greg Ward Boris Goldowsky James Mello Andreas Koenig Joe Smith Jonathan Pelletier Heiko Jansen Tong Zhu Paul Egan Ronald J Kimball James CE Johnson Bill Uhl Peter teStrake Harald Flaucher Simon Myers Gavin Carr Petya Kohts =head1 Inspiration and Assistance Gerard Hickey C Russ Allbery C Graham Barr C Andrew Tridgell and Paul Mackerras rsync(1) John Steele Esteele@nostrum.comE Philip Kizer Epckizer@nostrum.comE Larry Wall perl(1) I borrowed many clues on wrapping an external program from the PGP modules, and I would not have had such a useful tool to wrap except for the great work of the B authors. Thanks also to Graham Barr, the author of the libnet modules and many others, for looking over this code. Of course I must mention the other half of my brain, John Steele, and his good friend Philip Kizer for finding B and bringing it to my attention. And I would not have been able to enjoy writing useful tools if not for the creator of the B language. =head1 Copyrights Copyright (c) 1999-2005 Lee Eakin. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; File-Rsync-0.43/TODO0000644000076500007650000000117411122300237013377 0ustar leakinleakinBuild more tests Add example code to manpage Figure out a scheme for including extended docs. The new perl-style options add a great deal of flexibility. The ability to pass an array reference to the 'source' option, and the include/exclude options means you can build your own lists and pass them to the object when you are ready. I need to figure out a good (standard) way to include docs on this so people don't have to figure this out the hard way. Extended examples should also be included (like one using Find.pm to build a complex include/exclude list). Other suggestions welcome File-Rsync-0.43/config.in0000644000076500007650000000037511122300237014506 0ustar leakinleakin# -*- perl -*- # vim:ft=perl foldlevel=1 package File::Rsync::Config; require Exporter; use vars qw(@ISA @EXPORT %RsyncConfig); use strict; @EXPORT=qw(%RsyncConfig); @ISA=qw(Exporter); %RsyncConfig=( rsync_path => '/usr/local/bin/rsync', ); 1; File-Rsync-0.43/makepm.PL0000644000076500007650000000225611122300237014420 0ustar leakinleakin# makepm.PL -- Builds Rsync.pm from Rsync.in. -*- perl -*- sub find_rsync { my @dirs = map { s/^$/./; $_ } split (':', $ENV{PATH}); push (@dirs, qw(/usr/local/bin /usr/bin /opt/bin)); for my $dir (@dirs) { next unless -d $dir; next unless -x "$dir/rsync"; return "$dir/rsync"; } } $|=1; $RSYNC=&find_rsync; print <<'EOT'; File::Rsync needs to know the path to the rsync binary. This path is encoded in the installed module as the default path to rsync (it can be overridden at runtime). Please enter the full path to the rsync program or just hit Enter if the guess is correct. (If you always want the module to depend on the $PATH environment variable at runtime, just set the path to 'rsync' (this is not recommended)). EOT $RSYNC||='/usr/local/bin/rsync'; print "Path to rsync [$RSYNC]: "; my $ans=; chomp $ans; $RSYNC=$ans || $RSYNC; $RSYNC=~s/\\/\\\\/g; $RSYNC=~s/\'/\\\'/g; open IN,'config.in' or die "Cannot read config.in: $!\n"; open OUT,'>config.pm' or die "Cannot write config.pm: $!\n"; while () { if (/^(\s*rsync_path\s*=>)/) { print OUT "$1 '$RSYNC',\n" } else { print OUT } } close IN; close OUT; File-Rsync-0.43/test.pl0000644000076500007650000000422311242544050014227 0ustar leakinleakin#!/usr/local/bin/perl -w BEGIN { $|=1; print "1..6\n" } END { print("not ok 1\n"),exit 1 unless $loaded } use File::Rsync; use strict; use vars qw($loaded $fail); $loaded=1; $fail=0; warn "\nNOTE: expect 'badoption' message for test 7\n\n"; print "ok 1\n"; unless (-x $File::Rsync::RsyncConfig{rsync_path}) { $fail++; print "not ok 2\n"; warn "configured path to rsync binary ($File::Rsync::RsyncConfig{rsync_path}) does not exist or is not executable\n"; exit 1; } print "ok 2\n"; system qw(rm -rf destdir); # all in one { my $rs=File::Rsync->new(archive => 1, src => 'blib', dest => 'destdir'); unless ($rs) { print "not "; } else { my $ret=$rs->exec; ($ret == 1 && $rs->status == 0 && ! $rs->err) || ($fail++,print "not "); } print "ok 3\n"; } system qw(rm -rf destdir); # some in new, some in exec { my $rs=File::Rsync->new(archive => 1); unless ($rs) { $fail++; print "not "; } else { my $ret=$rs->exec(src => 'blib', dest => 'destdir'); ($ret == 1 && $rs->status == 0 && ! $rs->err) || ($fail++,print "not "); } print "ok 4\n"; } system qw(rm -rf destdir); # non-existant source { my $rs=File::Rsync->new(archive => 1); unless ($rs) { $fail++; print "not "; } else { no strict; my $ret=$rs->exec(src => 'some-non-existant-path-name', dest => 'destdir'); (@{$rs->err} >= 1 && $rs->err->[0] =~ /\bNo such file or directory\b/i) || ($fail++,print "not "); } print "ok 5\n"; } system qw(rm -rf destdir); # non-existant destination { my $rs=File::Rsync->new(archive => 1); unless ($rs) { $fail++; print "not "; } else { no strict; my $ret=$rs->exec(src => 'blib', dest => 'destdir/subdir'); ($ret == 0 && $rs->status != 0 && @{$rs->err} > 0 && ${$rs->err}[0] =~/\bNo such file or directory\b/i) || ($fail++,print "not "); } print "ok 6\n"; } system qw(rm -rf destdir); # invalid option { my $rs=File::Rsync->new(archive => 1, badoption => 1); $rs && ($fail++,print "not "); print "ok 7\n"; } system qw(rm -rf destdir); exit 1 if $fail;