File-Rsync-0.49/000755 000765 000024 00000000000 12670277613 014042 5ustar00leakinstaff000000 000000 File-Rsync-0.49/Changelog000644 000765 000024 00000056653 12670276660 015674 0ustar00leakinstaff000000 000000 Thu Mar 10 07:52:24 CST 2016 ( leakin at japh dot net ) * version 0.49: fix infun, broken since 0.46 refactor Michal Krupicka ( Michal dot Krupicka at skoda-auto dot cz ) reported that I broke the the input function (it worked differently from 0.45 and the documentation) when I converted to using IPC::Run3. This restores compatability with 0.45. Thanks Michal. Mon Sep 21 15:58:35 CDT 2015 ( leakin at dfw dot nostrum dot com ) * version 0.48: fix list option parsing Bill Shunn ( proprietor at shunn dot net ) found a bug in list option parsing that broke filters (and probably others as well). Fri Sep 11 08:36:39 CDT 2015 ( leakin at dfw dot nostrum dot com ) * version 0.47: fixed hash ref parsing Andreas Koenig ( andk at cpan dot org ) pointed out a problem with the hash ref compatibility code, and then graciously provided a test case to help me track down the problem. Added another test to confirm. Wed Jul 29 09:32:05 CDT 2015 ( leakin at dfw dot nostrum dot com ) * version 0.46: added support for new options up to 3.1.1 Max Maischein ( corion at corion dot net ) provided code and insight on how to support Windows OS, as well as some improved tests. IPC::Open3 was replaced with IPC::Run3 as part of this effort, thanks to Max for showing me this module. It simplified a big chunk of code and I was able to take advantage of its features in a few places (see infun and files-from below). Gavin Carr ( gavin at openfusion dot com dot au ) enlightened me some time ago of the advantages of ordered args with rsync. Order of args is now preserved. This is a long overdue change. Rsync itself performs some things differently based on the order of some args, hopefully this is a big improvement in functionality and doesn't break anyone. Passing options as a hash ref is now deprecated. Thanks Gavin, sorry it took me so long to implement. Petya Kohts ( kohts at yandex-team dot ru ) suggested code for srchost that would properly handle the rsync:// prefix Neil Hooey ( nhooey at gmail dot com) provided a better algorithm for the status method. Erez Schatz ( moonbuzz at gmail dot com ) sent improved pod formatting that should work better with pod2html The module debug option has become moddebug so it does not conflict with the rsync debug option. infun can now be an array ref, contents are fed to stdin via IPC::Run3 files-from can also be an array ref, this is handled in the module by setting infun to the array ref and --files-from='-' Added several more tests. Fri Nov 7 08:45:42 CST 2014 ( leakin at dfw dot nostrum dot com ) * version 0.45: removed 'use File::Rsync::Config', oops Thu Nov 6 10:03:01 CST 2014 ( leakin at dfw dot nostrum dot com ) * version 0.44: long overdue fix for automated builds, removed prompt for rsync path to use PATH environment instead. Tue 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 perception 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 ) * version 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 behavior 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 debugging 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 whether 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 subtraction. 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 separate 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 existence 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.49/Makefile.PL000644 000765 000024 00000001572 12553517777 016031 0ustar00leakinstaff000000 000000 # 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, 'File::Path' => 0, 'Test::More' => 0, 'IPC::Run3' => 0, }, PM => { 'Rsync.pm' => '$(INST_LIB)/File/Rsync.pm' }, dist => { COMPRESS => 'gzip', SUFFIX => 'gz' }, ); File-Rsync-0.49/MANIFEST000644 000765 000024 00000000231 12670277613 015167 0ustar00leakinstaff000000 000000 Changelog MANIFEST Makefile.PL README Rsync.pm TODO test.pl META.yml META.json Module JSON meta-data (added by MakeMaker) File-Rsync-0.49/META.json000644 000765 000024 00000002037 12670277613 015465 0ustar00leakinstaff000000 000000 { "abstract" : "Wrapper module for rsync(1) http://rsync.samba.org/", "author" : [ "Lee Eakin " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150005", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "File-Rsync", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "File::Path" : "0", "IPC::Run3" : "0", "Scalar::Util" : "0", "Test::More" : "0" } } }, "release_status" : "stable", "version" : "0.49", "x_serialization_backend" : "JSON::PP version 2.27200" } File-Rsync-0.49/META.yml000644 000765 000024 00000001174 12670277613 015316 0ustar00leakinstaff000000 000000 --- abstract: 'Wrapper module for rsync(1) http://rsync.samba.org/' author: - 'Lee Eakin ' build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150005' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: File-Rsync no_index: directory: - t - inc requires: File::Path: '0' IPC::Run3: '0' Scalar::Util: '0' Test::More: '0' version: '0.49' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' File-Rsync-0.49/README000644 000765 000024 00000003617 12670275717 014734 0ustar00leakinstaff000000 000000 File-Rsync - A wrapper module for rsync(1) http://rsync.samba.org/rsync/ ******************************************************************************* Copyright (C) 2000-2016 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. ******************************************************************************* Arg order is now preserved! Hopefully this provides better funtionality and more flexibility, and doesn't break anyone's code. Passing a hash reference is now deprecated, but forcing options to be a hash reference should restore old behavior if needed (option order not preserved, but source and dest are always the last 2 args). Windows is also now supported! See Changelog for details and credits. Updated to use $PATH environment variable to find rsync instead of hard-coding in the module since prompting breaks automatic builds and most modren systems should have rsync installed by now. It can be overridden using path-to-rsync at run time. 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.49/Rsync.pm000644 000765 000024 00000074514 12670104475 015504 0ustar00leakinstaff000000 000000 # -*- 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.008; # it might work with older versions of 5 but not tested use FileHandle; use IPC::Run3 'run3'; use Carp 'carp'; use Scalar::Util qw(blessed); use Data::Dumper; use strict; use vars qw($VERSION); $VERSION = '0.49'; =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:remotedir' ) 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. =head2 File::Rsync::new $obj = new File::Rsync; or $obj = File::Rsync->new; 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 style of a hash (key/value pairs) and are the same as the long options in I without the leading double-hyphen. Any leading single or double-hyphens are removed, and you may use underscore in place of hyphens in option names to simplify quoting and avoid possible equation parsing (subtraction). Although options are key/value pairs, as of version 0.46 the order is now preserved. Passing a hash reference is still supported for backwards compatibility, but is deprecated as order cannot be preserved for this case. An additional option of B also exists which can be used to override the using PATH environemt variable to find the rsync command binary, 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: these are B and B, which may be useful in protecting the paths from shell expansion (particularly useful for paths containing spaces). This wraps all source and/or destination paths in double-quotes to limit remote shell expansion. It is similar but not necessarily the same result as the B option in rsync itself. The B and B options take a function reference, 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. If options are passed as a hash reference (deprecated), the B needs an array reference as it's value since there cannot be duplicate keys in a hash. Since order cannot be preserved in a hash, this module currently limits the use of B or B together. They can be mixed together if options are in the form of a list or array ref. 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. As of version 0.46 the value of B may be an array reference. The contents of the array are passed to B the same as the below method using B but implemented inside the module. 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 options, 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 added 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. =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 = { # these are the boolean flags to rsync, all default off, including them # in the args list turns them on flag => { map { $_ => 0 } qw(8-bit-output acls append append-verify archive backup blocking-io checksum compress copy-dirlinks copy-links copy-unsafe-links crtimes cvs-exclude daemon del delay-updates delete delete-after delete-before delete-delay delete-during delete-excluded delete-missing-args devices dirs dry-run executability existing fake-super fileflags force force-change force-delete force-schange force-uchange from0 fuzzy group groups hard-links help hfs-compression ignore-errors ignore-existing ignore-missing-args ignore-non-existing ignore-times inc-recursive inplace ipv4 ipv6 keep-dirlinks links list-only msgs2stderr munge-links new-compress no-blocking-io no-detach no-devices no-dirs no-groups no-iconv no-implied-dirs no-inc-recursive no-links no-motd no-owner no-partial no-perms no-progress no-protect-args no-recursive no-relative no-specials no-super no-times no-whole-file numeric-ids old-compress old-dirs omit-dir-times omit-link-times owner partial perms preallocate progress protect-args protect-decmpfs prune-empty-dirs recursive relative remove-source-files safe-links size-only sparse specials stats super times update version whole-file xattrs) }, # these have simple scalar args we cannot easily check # use 'string' so I don't forget and leave keyword scalar unqouted string => { map { $_ => '' } qw(address backup-dir block-size bwlimit checksum-seed chown compress-level config contimeout csum-length debug files-from groupmap iconv info log-file log-file-format log-format max-delete max-size min-size modify-window only-write-batch out-format outbuf partial-dir password-file port protocol read-batch rsh rsync-path skip-compress sockopts suffix temp-dir timeout usermap write-batch) }, # 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 => { map { $_ => 0 } qw(human-readable itemize-changes one-file-system quiet verbose) }, # 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 list => { 'chmod' => [], 'compare-dest' => [], 'copy-dest' => [], 'dparam' => [], 'exclude' => [], 'exclude-from' => [], 'filter' => [], 'include' => [], 'include-from' => [], 'link-dest' => [], 'literal' => [], 'remote-option' => [], }, code => { # input/output user functions 'errfun' => undef, 'outfun' => undef, # function to prvide --*-from=- data via pipe 'infun' => undef, }, _perlopts => { # the path name to the rsync binary (default is to use $PATH) 'path-to-rsync' => 'rsync', # hostname of source, used if 'source' is an array reference 'srchost' => '', # double-quote source and/or destination paths 'quote-src' => 0, 'quote-dst' => 0, # whether or not to print debug statements 'moddebug' => 0, }, # 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, # stderr from last exec in array format (messages from remote rsync proc) '_err' => 0, # stdout from last exec in array format (messages from local rsync proc) '_out' => 0, # this flag changes error checking in 'exec' when called by 'list' '_list_mode' => 0, # this array used to preserve arg order '_args' => [], }; bless $self, $class; # bless it first so defopts can find out the class if (@_) { &defopts($self, @_) or return; } return $self; } =head2 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. =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 $href; my %OPT = (); # this is the hash we will return a ref to # make sure we are passed the proper number of args if (@_ == 1) { if (my $reftype = ref $_[0]) { if ($reftype eq 'HASH') { carp "$pkgname: hash reference is deprecated, use array or list." if $^W; @_ = %{$_[0]}; $href++; } elsif ($reftype eq 'ARRAY') { @_ = @{$_[0]}; } else { carp "$pkgname: invalid reference type ($reftype) option."; return; } } else { carp "$pkgname: invalid option ($_[0])."; return; } } if (@_ % 2) { carp "$pkgname: invalid number of options passed (must be key/value pairs)."; return; } # now process the options given, we handle debug first for (my $i = 0; $i < @_; $i += 2) { if ($_[$i] eq 'moddebug') { $OPT{moddebug} = $_[ $i + 1 ]; warn "setting debug flag\n" if $OPT{moddebug}; last; } } my @order; while (my ($inkey, $val) = splice @_, 0, 2) { (my $key = $inkey) =~ tr/_/-/; $key =~ s/^--?//; # remove any leading hyphens if found $key = 'source' if $key eq 'src'; $key = 'dest' if $key eq 'dst' or $key eq 'destination'; next if $key eq 'moddebug'; # we did this one already warn "processing option: $inkey\n" if $OPT{moddebug} or $self->{_perlopts}{moddebug}; if ( exists $self->{flag}{$key} or exists $self->{string}{$key} or exists $self->{counter}{$key} or exists $self->{_perlopts}{$key}) { if ($key eq 'files-from' and ref $val eq 'ARRAY') { push @order, $key, '-', 'infun', $val; # --files-from=- <\@ $OPT{$key} = '-'; $OPT{infun} = $val; } else { push @order, $key, $val; $OPT{$key} = $val; } next; } if (exists $self->{list}{$key} or $key eq 'source') { if (my $reftype = ref $val) { if ($reftype eq 'ARRAY') { push @order, $key, $val; $OPT{$key} = $val; next; } elsif ($key eq 'source' && blessed $val) { # if it's blessed, assume it returns a string $val = [$val]; push @order, $key, $val; $OPT{$key} = $val; next; } else { carp "$pkgname: invalid reference type for $inkey option."; return; } } elsif ($key eq 'source') { $val = [$val]; push @order, $key, $val; $OPT{$key} = $val; next; } else { carp "$pkgname: $inkey value is not a reference."; return; } } if ($key eq 'dest') { push @order, $key, $val; $OPT{$key} = $val; next; } if (exists $self->{code}{$key}) { if (ref $val eq 'CODE') { push @order, $key, $val; $OPT{$key} = $val; next; } elsif ($key eq 'infun' and ref $val eq 'ARRAY') { # IPC::Run3 lets us pass an array ref as stdin :) push @order, $key, $val; $OPT{$key} = $val; next; } else { carp "$pkgname: $inkey option is not a function reference."; return; } } carp "$pkgname: $inkey - unknown option."; return; } $OPT{_args} = \@order unless $href; return \%OPT; } sub _saveopts { # save the data from the hash passed in the object my $self = shift; my $pkgname = ref $self; my $opts = shift; return unless ref $opts eq 'HASH'; SO: for my $opt (keys %$opts) { for my $type (qw(flag string counter list code _perlopts)) { if (exists $self->{$type}{$opt}) { $self->{$type}{$opt} = $opts->{$opt}; next SO; } } if ( $opt eq 'source' or $opt eq 'dest' or $opt eq '_args') { $self->{$opt} = $opts->{$opt}; } else { carp "$pkgname: unknown option: $opt."; return; } } # end SO return 1; } =head2 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. =cut sub getcmd { my $self = shift; my $pkgname = ref $self; my $merged = $self; my $list = $self->{_list_mode}; $self->{_list_mode} = 0; 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 for my $type (qw(flag string counter list code _perlopts)) { for my $opt (keys %{$self->{$type}}) { $runopts{$type}{$opt} = $self->{$type}{$opt}; } } for my $opt (qw(source dest)) { $runopts{$opt} = $self->{$opt}; } @{$runopts{_args}} = @{$self->{_args}}; # now allow any args passed directly to exec to override OPT: for my $opt (keys %$execopts) { for my $type (qw(flag string counter list code _perlopts)) { if (exists $runopts{$type}{$opt}) { $runopts{$type}{$opt} = $execopts->{$opt}; next OPT; } } if ($opt eq '_args') { # only preserve order if we already have order push @{$runopts{$opt}}, @{$execopts->{$opt}} if @{$runopts{$opt}}; } elsif ($opt eq 'source' or $opt eq 'dest') { $runopts{$opt} = $execopts->{$opt}; } else { carp "$pkgname: unknown option: $opt."; return; } } $merged = \%runopts; } if ( !@{$merged->{_args}} # include and exclude allowed if ordered args && ( (@{$merged->{list}{exclude}} != 0) + (@{$merged->{list}{include}} != 0) + (@{$merged->{list}{filter}} != 0) > 1) ) { carp "$pkgname: 'exclude' and/or 'include' and/or 'filter' " . "options specified, only one allowed."; return; } my $srchost = $merged->{srchost}; $srchost .= ':' if $srchost and substr($srchost, 0, 8) ne 'rsync://'; # build the real command my @cmd = ($merged->{_perlopts}{'path-to-rsync'}); if (@{$merged->{_args}}) { # prefer ordered args if we have them my $gotsrc; for (my $e = 0; $e < @{$merged->{_args}}; $e += 2) { my $key = $merged->{_args}[$e]; my $val = $merged->{_args}[ $e + 1 ]; if ($key eq 'literal') { push @cmd, ref $val eq 'ARRAY' ? @$val : $val; } elsif (exists $merged->{flag}{$key}) { push @cmd, "--$key" if $val; } elsif (exists $merged->{string}{$key}) { push @cmd, "--$key=$val" if $val; } elsif (exists $merged->{counter}{$key}) { for (my $i = 0; $i < $val; $i++) { push @cmd, "--$key"; } } elsif (exists $merged->{list}{$key}) { push @cmd, ref $val eq 'ARRAY' ? map "--$key=$_", @$val : "--$key=$val"; } elsif ($key eq 'source') { if ($merged->{srchost}) { push @cmd, $srchost . join ' ', $merged->{'quote-src'} ? map ("\"$_\"", ref $val eq 'ARRAY' ? @$val : $val) : ref $val eq 'ARRAY' ? @$val : $val; } else { push @cmd, $merged->{'quote-src'} ? map ("\"$_\"", ref $val eq 'ARRAY' ? @$val : $val) : ref $val eq 'ARRAY' ? @$val : $val; } $gotsrc++; } elsif ($key eq 'dest') { if ($list) { if (not $gotsrc) { if ($merged->{srchost}) { push @cmd, $srchost; } else { carp "$pkgname: no 'source' specified."; return; } } } elsif (not $gotsrc) { carp "$pkgname: option 'dest' specified without 'source' option."; return; } else { push @cmd, $merged->{'quote-dst'} ? "\"$val\"" : $val; } } } } else { # we do a bunch of extra work here to support hash refs, # they don't work well here, no order, we do what we can # put any literal options first push @cmd, @{$merged->{list}{literal}} if @{$merged->{list}{literal}}; for my $opt (sort keys %{$merged->{flag}}) { push @cmd, "--$opt" if $merged->{flag}{$opt}; } for my $opt (sort keys %{$merged->{string}}) { push @cmd, "--$opt=$merged->{string}{$opt}" if $merged->{string}{$opt}; } for my $opt (sort keys %{$merged->{counter}}) { for (my $i = 0; $i < $merged->{counter}{$opt}; $i++) { push @cmd, "--$opt"; } } for my $opt (sort keys %{$merged->{list}}) { next if $opt eq 'literal'; for my $val (@{$merged->{list}{$opt}}) { push @cmd, "--$opt=$val"; } } if ($merged->{source}) { if ($merged->{srchost}) { push @cmd, $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, $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->{code}{infun}, $merged->{code}{outfun}, $merged->{code}{errfun}, $merged->{_perlopts}{moddebug} ) : \@cmd ); } =head2 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. =cut sub exec { my $self = shift; my ($cmd, $infun, $outfun, $errfun, $debug) = $self->getcmd(@_); return unless $cmd; warn "exec: @$cmd\n" if $debug; my $input; if (ref $infun eq 'CODE') { my $pid = open my $fh, '-|'; if ($pid) { # parent grabs output my @in = <$fh>; close $fh; chomp @in; $input = \@in; } else { # child runs infun &{$infun}; exit; } } else { $input = $infun; } run3($cmd, $input, \my $stdout, \my $stderr); $self->{_lastcmd} = $cmd; $self->{_realstatus} = $?; $self->{_status} = $? & 127 ? $? & 127 : $? >> 8; $self->{_out} = $stdout ? [ split /^/m, $stdout ] : ''; $self->{_err} = $stderr ? [ split /^/m, $stderr ] : ''; if ($outfun and $self->{_out}) { for (@{$self->{_out}}) { $outfun->($_, 'out') } } if ($errfun and $self->{_err}) { for (@{$self->{_err}}) { $errfun->($_, 'err') } } return ($self->{_status} ? 0 : 1); } =head2 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.) =cut sub list { my $self = shift; $self->{_list_mode}++; $self->exec(@_); if ($self->{_out}) { return (wantarray ? @{$self->{_out}} : $self->{_out}); } else { return; } } =head2 File::Rsync::status $rval = $obj->status; Returns the status from last I call right shifted 8 bits. =cut sub status { my $self = shift; return $self->{_status}; } =head2 File::Rsync::realstatus $rval = $obj->realstatus; Returns the real status from last I call (not right shifted). =cut sub realstatus { my $self = shift; return $self->{_realstatus}; } =head2 File::Rsync::err $aref = $obj->err; In 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. =cut sub err { my $self = shift; if ($self->{_err}) { return (wantarray ? @{$self->{_err}} : $self->{_err}); } else { return; } } =head2 File::Rsync::out $aref = $obj->out; 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. =cut sub out { my $self = shift; if ($self->{_out}) { return (wantarray ? @{$self->{_out}} : $self->{_out}); } else { return; } } =head2 File::Rsync::lastcmd $aref = $obj->lastcmd; 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. =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 Neil Hooey Erez Schatz Max Maischein =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-2015 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.49/test.pl000644 000765 000024 00000014064 12670051573 015356 0ustar00leakinstaff000000 000000 #!/usr/local/bin/perl -w END { print("not ok 1\n"), exit 1 unless $loaded } use File::Rsync; use File::Path 'rmtree'; use Test::More; use strict; use vars qw($loaded $fail); $loaded = 1; note "NOTE: expect 'badoption' message for test 7"; note "NOTE: expect 'deprecated' message for test 8"; ok($loaded, 'module loaded'); ok(whence('rsync'), 'rsync executable found'); rmtree('destdir'); # simple exec { my $rs = File::Rsync->new( archive => 1, src => 'blib', dest => 'destdir' ); my $ret; if ($rs) { my $cmd = $rs->getcmd; diag "Running [@$cmd]"; $ret = $rs->exec; } ok($rs && $ret == 1 && $rs->status == 0 && !$rs->err, 'simple exec'); } rmtree('destdir'); # exec with args { my $rs = File::Rsync->new(archive => 1); my $ret; if ($rs) { my $cmd = $rs->getcmd(src => 'blib', dest => 'destdir'); diag "Running [@$cmd]"; $ret = $rs->exec(src => 'blib', dest => 'destdir'); } ok($rs && $ret == 1 && $rs->status == 0 && !$rs->err, 'exec with args'); } rmtree('destdir'); # non-existant source { my $rs = File::Rsync->new(archive => 1); my $ret; if ($rs) { my $cmd = $rs->getcmd( src => 'some-non-existant-path-name', dest => 'destdir' ); diag "Running [@$cmd]"; $ret = $rs->exec(src => 'some-non-existant-path-name', dest => 'destdir'); } ok($rs && @{$rs->err} >= 1 && $rs->err->[0] =~ /\bNo such file or directory\b/i, 'non-existant source' ); } rmtree('destdir'); # non-existant destination { my $rs = File::Rsync->new(archive => 1); my $ret; if ($rs) { my $cmd = $rs->getcmd(src => 'blib', dest => 'destdir/subdir'); diag "Running [@$cmd]"; $ret = $rs->exec(src => 'blib', dest => 'destdir/subdir'); } ok($rs && $ret == 0 && $rs->status != 0 && @{$rs->err} > 0 && ${$rs->err}[0] =~ /\bNo such file or directory\b/i, 'non-existant destination' ); } rmtree('destdir'); # invalid option { my $rs = File::Rsync->new(archive => 1, badoption => 1); ok(!defined($rs), 'invalid option'); } # deprecated hash ref { local $^W = 1; # belt and suspenders (-w on #! too) my $rs = File::Rsync->new({archive => 1, src => 'blib', dest => 'destdir'}); ok($rs, 'deprecated hash ref'); } # mixed hash ref and non { my $ok; my $rs = File::Rsync->new({archive => 1}); if ($rs) { my $cmd = $rs->getcmd(src => 'blib', dest => 'destdir'); diag "checking [@$cmd]"; $ok = "@$cmd" eq 'rsync --archive blib destdir'; } ok($rs && $ok, 'mixed hash ref and non'); } SKIP: { skip "old rsync, no --files-from option", 2 unless have_files_from('rsync'); my @files = qw(lib/File/Rsync.pm); rmtree('destdir'); # files-from array ref { my $rs = File::Rsync->new( archive => 1, files_from => \@files, ); my $ok; my $missing; if ($rs) { my $cmd = $rs->getcmd(src => 'blib', dest => 'destdir'); diag "Running [@$cmd]"; $ok = $rs->exec(src => 'blib', dest => 'destdir'); if (not $ok) { diag "Ret: $ok"; diag "Return \$?: $rs->{realstatus}"; diag "Return exit code: $rs->{status}"; if ($rs->err) { diag $_ for @{$rs->err}; } } else { for my $entry (@files) { if (!$missing and !-f "destdir/$entry") { diag "Target file 'destdir/$entry' not found"; $missing++; } } } } ok($rs && $ok && !$missing, 'files-from array ref'); } rmtree('destdir'); # files-from infun my @copy_list = @files; my $rs = File::Rsync->new( archive => 1, files_from => '-', infun => sub { print join "\n", @copy_list }, ); my $ok; my $missing; if ($rs) { my $cmd = $rs->getcmd(src => 'blib', dest => 'destdir'); diag "Running [@$cmd]"; $ok = $rs->exec(src => 'blib', dest => 'destdir'); if (not $ok) { diag "Ret: $ok"; diag "Return \$?: $rs->{realstatus}"; diag "Return exit code: $rs->{status}"; if ($rs->err) { diag $_ for @{$rs->err}; } } else { for my $entry (@files) { if (!$missing and !-f "destdir/$entry") { diag "Target file 'destdir/$entry' not found"; $missing++; } } } } ok($rs && $ok && !$missing, 'files-from infun'); } rmtree('destdir'); # arg order tests { my $ok; my $rs = File::Rsync->new( archive => 1, itemize_changes => 1, omit_dir_times => 1, src => 'blib', dest => 'destdir' ); if ($rs) { my $cmd = $rs->getcmd; diag "Checking [@$cmd]"; $ok = "@$cmd" eq 'rsync --archive --itemize-changes --omit-dir-times blib destdir'; } ok($rs && $ok, 'ordered args'); } # arg order tests { my $ok; my $rs = File::Rsync->new( archive => 1, omit_dir_times => 1, itemize_changes => 1, no_perms => 1, exclude => ['.*.swp'], filter => [':- .gitignore'], 'delete' => 1, src => 'blib', dest => 'destdir' ); if ($rs) { my $cmd = $rs->getcmd; diag "Checking [@$cmd]"; $ok = "@$cmd" eq 'rsync --archive --omit-dir-times --itemize-changes --no-perms --exclude=.*.swp --filter=:- .gitignore --delete blib destdir'; } ok($rs && $ok, 'more ordered args'); } rmtree('destdir'); # one last time to be sure done_testing(); sub whence { my $cmd = shift; qx($cmd --version); # throw away output return if $?; return $cmd; } sub have_files_from { my $cmd = shift; my $rsync_version = `$cmd --version`; # We only care about major.minor, not the exact release here: $rsync_version =~ /version\s+(\d+\.\d+)\.\d+\s+/ or return; $rsync_version = $1; return $rsync_version > 2.6; } File-Rsync-0.49/TODO000644 000765 000024 00000000167 12556225614 014533 0ustar00leakinstaff000000 000000 Build more tests more code examples Find a way to cleanly support short options with long Other suggestions welcome