| 1 | package Test::Smoke::Syncer::Hardlink; | ||||||||||||||
| 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::Hardlink | ||||||||||||||
| 10 | |||||||||||||||
| 11 | This handles syncing by copying the source-tree from a local directory | ||||||||||||||
| 12 | using the B<link> function. This can be used as an alternative for | ||||||||||||||
| 13 | B<make distclean>. | ||||||||||||||
| 14 | |||||||||||||||
| 15 | Thanks to Nicholas Clark for donating this suggestion! | ||||||||||||||
| 16 | |||||||||||||||
| 17 | =cut | ||||||||||||||
| 18 | |||||||||||||||
| 19 | 12 | require File::Find; | |||||||||||||
| 20 | |||||||||||||||
| 21 | =head2 Test::Smoke::Syncer::Hardlink->new( %args ) | ||||||||||||||
| 22 | |||||||||||||||
| 23 | Keys for C<%args>: | ||||||||||||||
| 24 | |||||||||||||||
| 25 | * ddir: destination directory | ||||||||||||||
| 26 | * hdir: source directory | ||||||||||||||
| 27 | * v: verbose | ||||||||||||||
| 28 | |||||||||||||||
| 29 | =cut | ||||||||||||||
| 30 | |||||||||||||||
| 31 | =head2 $syncer->sync( ) | ||||||||||||||
| 32 | |||||||||||||||
| 33 | C<sync()> uses the B<File::Find> module to make the hardlink forest in {ddir}. | ||||||||||||||
| 34 | |||||||||||||||
| 35 | =cut | ||||||||||||||
| 36 | |||||||||||||||
| 37 | 2 | ▶ | sub sync { | ||||||||||||
|
Subroutine
sync: called CC=3 SCAR=11.5
Pod
documented
| |||||||||||||||
| 38 | 2 | my $self = shift; | |||||||||||||
| 39 | |||||||||||||||
| 40 | 2 | $self->pre_sync; | |||||||||||||
| 41 | 2 | ▶ | require File::Copy unless $self->{haslink}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 42 | |||||||||||||||
| 43 | 2 | ▶ | -d $self->{ddir} or File::Path::mkpath( $self->{ddir} ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | |||||||||||||||
| 45 | 2 | my $source_dir = File::Spec->canonpath( $self->{hdir} ); | |||||||||||||
| 46 | |||||||||||||||
| 47 | 16 | ▶ | File::Find::find( sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=25.1
| |||||||||||||||
| 48 | 16 | my $dest = File::Spec->abs2rel( $File::Find::name, $source_dir ); | |||||||||||||
| 49 | # nasty thing in older File::Spec::Win32::abs2rel() | ||||||||||||||
| 50 | 16 | ▶ | $^O eq 'MSWin32' and $dest =~ s|^[a-z]:(?![/\\])||i; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 51 | 16 | $dest = File::Spec->catfile( $self->{ddir}, $dest ); | |||||||||||||
| 52 | 16 | ▶ | if ( -d ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 4 | mkdir $dest, (stat _)[2] & 07777; | |||||||||||||
| 54 | } else { | ||||||||||||||
| 55 | 12 | ▶ | -e $dest and 1 while unlink $dest; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 56 | 12 | ▶ | $self->{v} > 1 and print "link $_ $dest"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | my $ok = $self->{haslink} | ||||||||||||||
| 58 | 12 | ▶ | ? link $_, $dest | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 59 | : File::Copy::copy( $_, $dest ); | ||||||||||||||
| 60 | 12 | ▶ | if ( $self->{v} > 1 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 61 | 0 | ▶ | print $ok ? " OK\n" : " $!\n"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | } | ||||||||||||||
| 63 | } | ||||||||||||||
| 64 | 2 | }, $source_dir ); | |||||||||||||
| 65 | |||||||||||||||
| 66 | 2 | $self->clean_from_directory( $source_dir ); | |||||||||||||
| 67 | |||||||||||||||
| 68 | 2 | $self->post_sync; | |||||||||||||
| 69 | 2 | return $self->check_dot_patch(); | |||||||||||||
| 70 | } | ||||||||||||||
| 71 | |||||||||||||||
| 72 | 12 | 1; | |||||||||||||
| 73 | |||||||||||||||
| 74 | =head1 COPYRIGHT | ||||||||||||||
| 75 | |||||||||||||||
| 76 | (c) 2002-2013, All rights reserved. | ||||||||||||||
| 77 | |||||||||||||||
| 78 | * Abe Timmerman <abeltje@cpan.org> | ||||||||||||||
| 79 | |||||||||||||||
| 80 | This library is free software; you can redistribute it and/or modify | ||||||||||||||
| 81 | it under the same terms as Perl itself. | ||||||||||||||
| 82 | |||||||||||||||
| 83 | See: | ||||||||||||||
| 84 | |||||||||||||||
| 85 | * <http://www.perl.com/perl/misc/Artistic.html>, | ||||||||||||||
| 86 | * <http://www.gnu.org/copyleft/gpl.html> | ||||||||||||||
| 87 | |||||||||||||||
| 88 | This program is distributed in the hope that it will be useful, | ||||||||||||||
| 89 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||
| 90 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||
| 91 | |||||||||||||||
| 92 | =cut | ||||||||||||||