| 1 | package Dackup::Target::Filesystem; | ||||||||||||||||||
| 2 | 1 | ▶ | use Moose; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 3 | 1 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 1 | ▶ | use MooseX::Types::Path::Class; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 1 | ▶ | use Digest::MD5::File qw(file_md5_hex); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | 1 | ▶ | use File::Copy; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | 1 | ▶ | use Path::Class; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | 1 | extends 'Dackup::Target'; | |||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | 1 | has 'prefix' => ( | |||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||
| 13 | isa => 'Path::Class::Dir', | ||||||||||||||||||
| 14 | required => 1, | ||||||||||||||||||
| 15 | coerce => 1, | ||||||||||||||||||
| 16 | ); | ||||||||||||||||||
| 17 | |||||||||||||||||||
| 18 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | 4 | ▶ | sub entries { | ||||||||||||||||
|
Subroutine
entries: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||
| 21 | 4 | my $self = shift; | |||||||||||||||||
| 22 | 4 | my $dackup = $self->dackup; | |||||||||||||||||
| 23 | 4 | my $prefix = $self->prefix; | |||||||||||||||||
| 24 | 4 | my $cache = $dackup->cache; | |||||||||||||||||
| 25 | |||||||||||||||||||
| 26 | 4 | ▶ | return [] unless -d $prefix; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 27 | |||||||||||||||||||
| 28 | 4 | my $file_stream = Data::Stream::Bulk::Path::Class->new( | |||||||||||||||||
| 29 | dir => Path::Class::Dir->new($prefix), | ||||||||||||||||||
| 30 | only_files => 1, | ||||||||||||||||||
| 31 | ); | ||||||||||||||||||
| 32 | |||||||||||||||||||
| 33 | 4 | my @entries; | |||||||||||||||||
| 34 | 4 | ▶ | until ( $file_stream->is_done ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 35 | 4 | foreach my $filename ( $file_stream->items ) { | |||||||||||||||||
| 36 | |||||||||||||||||||
| 37 | # Do not backup the cache db | ||||||||||||||||||
| 38 | 11 | ▶ | next if $filename->basename() eq 'dackup.db'; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 39 | |||||||||||||||||||
| 40 | 9 | my $key = $filename->relative($prefix)->stringify; | |||||||||||||||||
| 41 | |||||||||||||||||||
| 42 | 9 | ▶ | my $stat = $filename->stat | ||||||||||||||||
|
Condition50%1/2
$filename->stat || confess("Unable to stat $filename")
MC/DC0%0/1
$filename->stat || confess("Unable to stat $filename")
$filename->stat
Truth table50%1/2
A
A= $filename->stat
| |||||||||||||||||||
| 43 | || confess "Unable to stat $filename"; | ||||||||||||||||||
| 44 | 9 | my $ctime = $stat->ctime; | |||||||||||||||||
| 45 | 9 | my $mtime = $stat->mtime; | |||||||||||||||||
| 46 | 9 | my $size = $stat->size; | |||||||||||||||||
| 47 | 9 | my $inodenum = $stat->ino; | |||||||||||||||||
| 48 | 9 | my $cachekey = "$filename:$ctime,$mtime,$size,$inodenum"; | |||||||||||||||||
| 49 | |||||||||||||||||||
| 50 | 9 | my $md5_hex = $cache->get($cachekey); | |||||||||||||||||
| 51 | 9 | ▶ | if ($md5_hex) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 52 | } else { | ||||||||||||||||||
| 53 | 6 | $md5_hex = file_md5_hex($filename); | |||||||||||||||||
| 54 | 6 | $cache->set( $cachekey, $md5_hex ); | |||||||||||||||||
| 55 | } | ||||||||||||||||||
| 56 | |||||||||||||||||||
| 57 | 9 | my $entry = Dackup::Entry->new( | |||||||||||||||||
| 58 | { key => $key, | ||||||||||||||||||
| 59 | md5_hex => $md5_hex, | ||||||||||||||||||
| 60 | size => $size, | ||||||||||||||||||
| 61 | } | ||||||||||||||||||
| 62 | ); | ||||||||||||||||||
| 63 | 9 | push @entries, $entry; | |||||||||||||||||
| 64 | } | ||||||||||||||||||
| 65 | } | ||||||||||||||||||
| 66 | 4 | return \@entries; | |||||||||||||||||
| 67 | } | ||||||||||||||||||
| 68 | |||||||||||||||||||
| 69 | 6 | ▶ | sub filename { | ||||||||||||||||
|
Subroutine
filename: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||
| 70 | 6 | my ( $self, $entry ) = @_; | |||||||||||||||||
| 71 | 6 | return file( $self->prefix, $entry->key ); | |||||||||||||||||
| 72 | } | ||||||||||||||||||
| 73 | |||||||||||||||||||
| 74 | 0 | ▶ | sub name { | ||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 75 | 0 | my ( $self, $entry ) = @_; | |||||||||||||||||
| 76 | 0 | return 'file://' . file( $self->prefix, $entry->key ); | |||||||||||||||||
| 77 | } | ||||||||||||||||||
| 78 | |||||||||||||||||||
| 79 | 3 | ▶ | sub update { | ||||||||||||||||
|
Subroutine
update: called CC=6 SCAR=26.0
Pod
undocumented
| |||||||||||||||||||
| 80 | 3 | my ( $self, $source, $entry ) = @_; | |||||||||||||||||
| 81 | 3 | my $source_type = ref($source); | |||||||||||||||||
| 82 | 3 | my $destination_filename = $self->filename($entry); | |||||||||||||||||
| 83 | 3 | $destination_filename->parent->mkpath; | |||||||||||||||||
| 84 | |||||||||||||||||||
| 85 | 3 | ▶ | if ( $source_type eq 'Dackup::Target::Filesystem' ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 86 | 3 | my $source_filename = $source->filename($entry); | |||||||||||||||||
| 87 | 3 | ▶ | copy( $source_filename->stringify, $destination_filename->stringify ) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 88 | || confess( | ||||||||||||||||||
| 89 | "Error copying $source_filename to $destination_filename: $!"); | ||||||||||||||||||
| 90 | } elsif ( $source_type eq 'Dackup::Target::S3' ) { | ||||||||||||||||||
| 91 | 0 | my $source_object = $source->object($entry); | |||||||||||||||||
| 92 | 0 | $source_object->get_filename( $destination_filename->stringify ); | |||||||||||||||||
| 93 | } elsif ( $source_type eq 'Dackup::Target::SSH' ) { | ||||||||||||||||||
| 94 | 0 | my $source_filename = $source->filename($entry); | |||||||||||||||||
| 95 | 0 | ▶ | $source->ssh->scp_get( "$source_filename", "$destination_filename" ) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 96 | || die "scp failed: " . $source->ssh->error; | ||||||||||||||||||
| 97 | } else { | ||||||||||||||||||
| 98 | 0 | confess "Do not know how to update from $source_type"; | |||||||||||||||||
| 99 | } | ||||||||||||||||||
| 100 | } | ||||||||||||||||||
| 101 | |||||||||||||||||||
| 102 | 0 | ▶ | sub delete { | ||||||||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||
| 103 | 0 | my ( $self, $entry ) = @_; | |||||||||||||||||
| 104 | 0 | my $filename = $self->filename($entry); | |||||||||||||||||
| 105 | 0 | ▶ | unlink($filename) || confess("Error deleting $filename: $!"); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 106 | } | ||||||||||||||||||
| 107 | |||||||||||||||||||
| 108 | 1 | 1; | |||||||||||||||||
| 109 | |||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||