| 1 | package Test::Smoke::Syncer::Rsync; | ||||||||||||||
| 2 | 12 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 12 | our $VERSION = '0.029'; | |||||||||||||
| 6 | |||||||||||||||
| 7 | 12 | ▶ | use base 'Test::Smoke::Syncer::Base'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | =head1 Test::Smoke::Syncer::Rsync | ||||||||||||||
| 10 | |||||||||||||||
| 11 | This handles syncing with the B<rsync> program. | ||||||||||||||
| 12 | It should only be visible from the "parent-package" so no direct | ||||||||||||||
| 13 | user-calls on this. | ||||||||||||||
| 14 | |||||||||||||||
| 15 | =cut | ||||||||||||||
| 16 | |||||||||||||||
| 17 | 12 | ▶ | use Cwd; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 18 | 12 | ▶ | use Test::Smoke::LogMixin; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | 12 | ▶ | use Test::Smoke::Util::Execute; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | 12 | ▶ | use Text::ParseWords; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 21 | |||||||||||||||
| 22 | =head2 Test::Smoke::Syncer::Rsync->new( %args ) | ||||||||||||||
| 23 | |||||||||||||||
| 24 | This crates the new object. Keys for C<%args>: | ||||||||||||||
| 25 | |||||||||||||||
| 26 | * ddir: destination directory ( ./perl-current ) | ||||||||||||||
| 27 | * source: the rsync source ( ftp.linux.activestate.com::perl-current ) | ||||||||||||||
| 28 | * opts: the options for rsync ( -az --delete ) | ||||||||||||||
| 29 | * rsync: the full path to the rsync program ( rsync ) | ||||||||||||||
| 30 | * v: verbose | ||||||||||||||
| 31 | |||||||||||||||
| 32 | =head2 $rsync->pre_sync() | ||||||||||||||
| 33 | |||||||||||||||
| 34 | Create the destination directory is it doesn't exist. | ||||||||||||||
| 35 | |||||||||||||||
| 36 | =cut | ||||||||||||||
| 37 | |||||||||||||||
| 38 | 0 | ▶ | sub pre_sync { | ||||||||||||
|
Subroutine
pre_sync: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 39 | 0 | my $self = shift; | |||||||||||||
| 40 | 0 | ▶ | if (! -d $self->{ddir}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | 0 | require File::Path; | |||||||||||||
| 42 | 0 | open my $fh, '>', \my $output; | |||||||||||||
| 43 | 0 | my $stdout = select $fh; | |||||||||||||
| 44 | 0 | File::Path::mkpath($self->{ddir}, $self->verbose); | |||||||||||||
| 45 | 0 | select $stdout; | |||||||||||||
| 46 | 0 | $self->log_info($output); | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | 0 | $self->SUPER::pre_sync; | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | =head2 $object->sync( ) | ||||||||||||||
| 52 | |||||||||||||||
| 53 | Do the actual sync using a call to the B<rsync> program. | ||||||||||||||
| 54 | |||||||||||||||
| 55 | B<rsync> can also be used as a smart version of copy. If you | ||||||||||||||
| 56 | use a local directory to rsync from, make sure the destination path | ||||||||||||||
| 57 | ends with a I<path separator>! (This does not seem to work for source | ||||||||||||||
| 58 | paths mounted via NFS.) | ||||||||||||||
| 59 | |||||||||||||||
| 60 | =cut | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 0 | ▶ | sub sync { | ||||||||||||
|
Subroutine
sync: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||
| 64 | 0 | $self->pre_sync; | |||||||||||||
| 65 | |||||||||||||||
| 66 | my $rsync = Test::Smoke::Util::Execute->new( | ||||||||||||||
| 67 | command => $self->{rsync}, | ||||||||||||||
| 68 | 0 | verbose => $self->verbose, | |||||||||||||
| 69 | ); | ||||||||||||||
| 70 | 0 | my $cwd = cwd(); | |||||||||||||
| 71 | 0 | ▶ | if (! chdir $self->{ddir}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 72 | 0 | require Carp; | |||||||||||||
| 73 | 0 | Carp::croak( "[rsync] Cannot chdir($self->{ddir}): $!" ); | |||||||||||||
| 74 | }; | ||||||||||||||
| 75 | my $rsyncout = $rsync->run( | ||||||||||||||
| 76 | shellwords($self->{opts}), | ||||||||||||||
| 77 | ($self->verbose ? "-v" : ""), | ||||||||||||||
| 78 | $self->{source}, | ||||||||||||||
| 79 | 0 | ▶ | File::Spec->curdir, | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 80 | ($self->verbose ? "" : ">" . File::Spec->devnull) | ||||||||||||||
| 81 | ); | ||||||||||||||
| 82 | 0 | $self->log_debug($rsyncout); | |||||||||||||
| 83 | |||||||||||||||
| 84 | 0 | ▶ | if (my $err = $rsync->exitcode ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 85 | 0 | require Carp; | |||||||||||||
| 86 | 0 | Carp::carp( "Problem during rsync ($err)" ); | |||||||||||||
| 87 | } | ||||||||||||||
| 88 | |||||||||||||||
| 89 | 0 | ▶ | if ($self->is_git_dir()) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 90 | 0 | $self->make_dot_patch(); | |||||||||||||
| 91 | } | ||||||||||||||
| 92 | |||||||||||||||
| 93 | 0 | chdir $cwd; | |||||||||||||
| 94 | |||||||||||||||
| 95 | 0 | my $plevel = $self->check_dot_patch; | |||||||||||||
| 96 | 0 | $self->post_sync; | |||||||||||||
| 97 | 0 | return $plevel; | |||||||||||||
| 98 | } | ||||||||||||||
| 99 | |||||||||||||||
| 100 | 12 | 1; | |||||||||||||
| 101 | |||||||||||||||
| 102 | =head1 COPYRIGHT | ||||||||||||||
| 103 | |||||||||||||||
| 104 | (c) 2002-2013, All rights reserved. | ||||||||||||||
| 105 | |||||||||||||||
| 106 | * Abe Timmerman <abeltje@cpan.org> | ||||||||||||||
| 107 | |||||||||||||||
| 108 | This library is free software; you can redistribute it and/or modify | ||||||||||||||
| 109 | it under the same terms as Perl itself. | ||||||||||||||
| 110 | |||||||||||||||
| 111 | See: | ||||||||||||||
| 112 | |||||||||||||||
| 113 | * <http://www.perl.com/perl/misc/Artistic.html>, | ||||||||||||||
| 114 | * <http://www.gnu.org/copyleft/gpl.html> | ||||||||||||||
| 115 | |||||||||||||||
| 116 | This program is distributed in the hope that it will be useful, | ||||||||||||||
| 117 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||
| 118 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||
| 119 | |||||||||||||||
| 120 | =cut | ||||||||||||||