| 1 | # support module for helping test brackup | ||||||||||||||||||||
| 2 | package Brackup::Test; | ||||||||||||||||||||
| 3 | 12 | require Exporter; | |||||||||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 12 | ▶ | use vars qw(@ISA @EXPORT); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 12 | @ISA = qw(Exporter); | |||||||||||||||||||
| 7 | 12 | @EXPORT = qw(do_backup do_restore ok_dirs_match ok_files_match); | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 12 | ▶ | use Test::More; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 12 | ▶ | use FindBin qw($Bin); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 12 | ▶ | use Brackup::Util qw(tempdir tempfile); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 12 | ▶ | use File::Find; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 12 | ▶ | use File::stat (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 12 | ▶ | use Cwd; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 12 | ▶ | use Brackup::DecryptedFile; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 12 | ▶ | use Digest::SHA1 qw/sha1_hex/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 12 | ▶ | use Brackup; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 12 | ▶ | my $has_diff = eval "use Text::Diff; 1;"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 12 | my @to_unlink; | |||||||||||||||||||
| 23 | 12 | my $par_pid = $$; | |||||||||||||||||||
| 24 | 12 | ▶ | END { | ||||||||||||||||||
|
Subroutine
END: called CC=3 SCAR=12.0
| |||||||||||||||||||||
| 25 | 12 | ▶ | if ($$ == $par_pid) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 12 | ▶ | my $rv = unlink @to_unlink unless $ENV{BRACKUP_TEST_NOCLEANUP}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | # Set the gpg directory, so we don't rely on users having a ~/.gnupg | ||||||||||||||||||||
| 31 | 12 | $ENV{GNUPGHOME} = tempdir( CLEANUP => 1 ); | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 5 | ▶ | sub do_backup { | ||||||||||||||||||
|
Subroutine
do_backup: called CC=10 SCAR=23.3
Pod
undocumented
| |||||||||||||||||||||
| 34 | 5 | my %opts = @_; | |||||||||||||||||||
| 35 | 5 | ▶ | my $with_confsec = delete $opts{'with_confsec'} || sub {}; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
delete $opts{'with_confsec'} || sub {
}
MC/DC0%0/2
delete $opts{'with_confsec'} || sub {
}
delete $opts{'with_confsec'}
sub {
}
Truth table33%1/3
A || B
A= delete $opts{'with_confsec'}B= sub {
}
| |||||||||||||||||||||
| 36 | 5 | ▶ | my $with_targetsec = delete $opts{'with_targetsec'} || sub {}; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Condition66%2/3
delete $opts{'with_targetsec'} || sub {
}
MC/DC0%0/2
delete $opts{'with_targetsec'} || sub {
}
delete $opts{'with_targetsec'}
sub {
}
Truth table66%2/3
A || B
A= delete $opts{'with_targetsec'}B= sub {
}
| |||||||||||||||||||||
| 37 | 5 | ▶ | my $with_root = delete $opts{'with_root'} || sub {}; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
Condition33%1/3
delete $opts{'with_root'} || sub {
}
MC/DC0%0/2
delete $opts{'with_root'} || sub {
}
delete $opts{'with_root'}
sub {
}
Truth table33%1/3
A || B
A= delete $opts{'with_root'}B= sub {
}
| |||||||||||||||||||||
| 38 | 5 | my $target = delete $opts{'with_target'}; | |||||||||||||||||||
| 39 | 5 | ▶ | die if %opts; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 5 | my $initer = shift; | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 5 | my $conf = Brackup::Config->new; | |||||||||||||||||||
| 44 | 5 | my $confsec; | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 5 | $confsec = Brackup::ConfigSection->new("SOURCE:test_root"); | |||||||||||||||||||
| 47 | 5 | $with_confsec->($confsec); | |||||||||||||||||||
| 48 | 5 | $conf->add_section($confsec); | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 5 | my $root = $conf->load_root("test_root"); | |||||||||||||||||||
| 51 | 5 | ok($root, "have a source root"); | |||||||||||||||||||
| 52 | 5 | $with_root->($root); | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 5 | ▶ | unless ($target) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | 4 | ▶ | my $backup_dir = tempdir( CLEANUP => $ENV{BRACKUP_TEST_NOCLEANUP} ? 0 : 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 4 | ok_dir_empty($backup_dir); | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 4 | my ($inv_fh, $inv_filename) = tempfile(); | |||||||||||||||||||
| 59 | 4 | close($inv_fh); | |||||||||||||||||||
| 60 | 4 | push @to_unlink, $inv_filename; | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 4 | $confsec = Brackup::ConfigSection->new("TARGET:test_restore"); | |||||||||||||||||||
| 64 | 4 | $with_targetsec->($confsec); | |||||||||||||||||||
| 65 | 4 | ▶ | $confsec->add("type" => "Filesystem") unless exists $confsec->{type}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | 4 | $confsec->add("inventorydb_file" => $inv_filename); | |||||||||||||||||||
| 67 | 4 | $confsec->add("path" => $backup_dir); | |||||||||||||||||||
| 68 | 4 | $conf->add_section($confsec); | |||||||||||||||||||
| 69 | 4 | $target = $conf->load_target("test_restore", testmode => 1); | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 5 | ok($target, "have a target ($target)"); | |||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 5 | my $backup = Brackup::Backup->new( | |||||||||||||||||||
| 75 | root => $root, | ||||||||||||||||||||
| 76 | target => $target, | ||||||||||||||||||||
| 77 | savefiles => 1, | ||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||
| 79 | 5 | ok($backup, "have a backup object"); | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 5 | my ($meta_fh, $meta_filename) = tempfile(); | |||||||||||||||||||
| 82 | 5 | ok(-e $meta_filename, "metafile exists"); | |||||||||||||||||||
| 83 | 5 | push @to_unlink, $meta_filename; | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 5 | ok(eval { $backup->backup($meta_filename) }, "backup succeeded"); | |||||||||||||||||||
| 86 | 5 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | 0 | warn "Died running backup: $@\n"; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | 5 | ok(-s $meta_filename, "backup file has size"); | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 5 | check_inventory_db($target, [$root->gpg_args]); | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 5 | ▶ | return wantarray ? ($meta_filename, $backup, $target) : $meta_filename; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 6 | ▶ | sub check_inventory_db { | ||||||||||||||||||
|
Subroutine
check_inventory_db: called CC=11 SCAR=25.7
Pod
undocumented
| |||||||||||||||||||||
| 97 | 6 | my ($target, $gpg_args) = @_; | |||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 6 | my $inv_db_file; | |||||||||||||||||||
| 100 | 6 | eval { | |||||||||||||||||||
| 101 | 6 | ▶ | my $inv_db = $target->inventory_db or die 'cannot open inventory db'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | 6 | ▶ | $inv_db_file = $inv_db->backing_file ? (' ' . $inv_db->backing_file) : ''; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 6 | ▶ | while (my ($key, $value) = $inv_db->each) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 105 | 74 | my ($raw_dig, $gpg_rcpt) = split /;/, $key; | |||||||||||||||||||
| 106 | 74 | my ($enc_dig, $enc_size, $range) = split /\s+/, $value; | |||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | # check the stored data | ||||||||||||||||||||
| 109 | 74 | ▶ | my $dataref = $target->load_chunk($enc_dig) or die "cannot load chunk $enc_dig"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 110 | 74 | ▶ | length $$dataref == $enc_size or die "chunk $enc_dig has wrong size, not $enc_size"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | 74 | ▶ | $enc_dig eq "sha1:".sha1_hex($$dataref) or die "chunk $enc_dig has wrong digest"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | # if we are in a composite chunk, keep only the part we want | ||||||||||||||||||||
| 114 | 74 | ▶ | if($range) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 115 | 5 | my ($from, $to) = split '-', $range; | |||||||||||||||||||
| 116 | 5 | my $part = substr $$dataref, $from, $to-$from; | |||||||||||||||||||
| 117 | 5 | $dataref = \$part; | |||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | # decrypt if encrypted | ||||||||||||||||||||
| 121 | 74 | my $dec_ref; | |||||||||||||||||||
| 122 | 74 | ▶ | if($gpg_rcpt =~ /^to=(.*)$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 123 | 0 | my $meta = { 'GPG-Recipient' => $1 }; | |||||||||||||||||||
| 124 | 0 | local @Brackup::GPG_ARGS = @$gpg_args; | |||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 0 | $dec_ref = Brackup::Decrypt::decrypt_data($dataref, meta => $meta); | |||||||||||||||||||
| 127 | } else { | ||||||||||||||||||||
| 128 | 74 | $dec_ref = $dataref; | |||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | # check the raw data | ||||||||||||||||||||
| 132 | 74 | ▶ | $raw_dig eq "sha1:".sha1_hex($$dec_ref) or die "chunk $enc_dig has wrong raw digest"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 133 | } | ||||||||||||||||||||
| 134 | }; | ||||||||||||||||||||
| 135 | 6 | ▶ | ok(!$@, "inventory db$inv_db_file is good") or diag($@); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 7 | ▶ | sub do_restore { | ||||||||||||||||||
|
Subroutine
do_restore: called CC=7 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||
| 139 | 7 | my ($backup_file, %opts) = @_; | |||||||||||||||||||
| 140 | 7 | ▶ | my $prefix = delete $opts{'prefix'} || ""; # default is restore everything | ||||||||||||||||||
|
Condition100%2/2
delete $opts{'prefix'} || ''
MC/DC100%1/1
delete $opts{'prefix'} || ''
delete $opts{'prefix'}
Truth table100%2/2
A
A= delete $opts{'prefix'}
| |||||||||||||||||||||
| 141 | 7 | my $restore_should_die = delete $opts{'restore_should_die'}; | |||||||||||||||||||
| 142 | 7 | ▶ | die if %opts; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 143 | 7 | ▶ | my $restore_dir = tempdir( CLEANUP => $ENV{BRACKUP_TEST_NOCLEANUP} ? 0 : 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 144 | 7 | ok_dir_empty($restore_dir); | |||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 7 | my $restore = Brackup::Restore->new( | |||||||||||||||||||
| 147 | to => $restore_dir, | ||||||||||||||||||||
| 148 | prefix => $prefix, | ||||||||||||||||||||
| 149 | file => $backup_file, | ||||||||||||||||||||
| 150 | ); | ||||||||||||||||||||
| 151 | 7 | ok($restore, "have restore object"); | |||||||||||||||||||
| 152 | 7 | my $rv = eval { $restore->restore; }; | |||||||||||||||||||
| 153 | 7 | ▶ | if ($restore_should_die) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 154 | 1 | ▶ | ok(! defined $rv, "restore died: $@") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 155 | or die "restore unexpectedly succeeded"; | ||||||||||||||||||||
| 156 | 1 | return; | |||||||||||||||||||
| 157 | } | ||||||||||||||||||||
| 158 | else { | ||||||||||||||||||||
| 159 | 6 | ▶ | ok($rv, "did the restore") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 160 | or die "restore failed: $@"; | ||||||||||||||||||||
| 161 | 6 | return $restore_dir; | |||||||||||||||||||
| 162 | } | ||||||||||||||||||||
| 163 | } | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | 4 | ▶ | sub ok_dirs_match { | ||||||||||||||||||
|
Subroutine
ok_dirs_match: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 166 | 4 | my ($after, $before) = @_; | |||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | 4 | my $pre_ls = dir_structure($before); | |||||||||||||||||||
| 169 | 4 | my $post_ls = dir_structure($after); | |||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 4 | ▶ | if ($has_diff) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 172 | 12 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 173 | 4 | my $pre_dump = Dumper($pre_ls); | |||||||||||||||||||
| 174 | 4 | my $post_dump = Dumper($post_ls); | |||||||||||||||||||
| 175 | 4 | my $diff = Text::Diff::diff(\$pre_dump, \$post_dump); | |||||||||||||||||||
| 176 | 4 | is($diff, "", "dirs match"); | |||||||||||||||||||
| 177 | } else { | ||||||||||||||||||||
| 178 | 0 | is_deeply($post_ls, $pre_ls, "dirs match"); | |||||||||||||||||||
| 179 | } | ||||||||||||||||||||
| 180 | } | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | 2 | ▶ | sub ok_files_match { | ||||||||||||||||||
|
Subroutine
ok_files_match: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 183 | 2 | my ($after, $before) = @_; | |||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | 2 | my $pre_ls = file_meta($before); | |||||||||||||||||||
| 186 | 2 | my $post_ls = file_meta($after); | |||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | 2 | ▶ | if ($has_diff) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 189 | 12 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 190 | 2 | my $pre_dump = Dumper($pre_ls); | |||||||||||||||||||
| 191 | 2 | my $post_dump = Dumper($post_ls); | |||||||||||||||||||
| 192 | 2 | my $diff = Text::Diff::diff(\$pre_dump, \$post_dump); | |||||||||||||||||||
| 193 | 2 | is($diff, "", "files match"); | |||||||||||||||||||
| 194 | } else { | ||||||||||||||||||||
| 195 | 0 | is_deeply($post_ls, $pre_ls, "files match"); | |||||||||||||||||||
| 196 | } | ||||||||||||||||||||
| 197 | } | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | 11 | ▶ | sub ok_dir_empty { | ||||||||||||||||||
|
Subroutine
ok_dir_empty: called CC=3 SCAR=12.7
Pod
undocumented
| |||||||||||||||||||||
| 200 | 11 | my $dir = shift; | |||||||||||||||||||
| 201 | 0 | ▶ | unless (-d $dir) { ok(0, "not a dir"); return; } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 202 | 11 | ▶ | opendir(my $dh, $dir) or die "failed to opendir: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 203 | 11 | is_deeply([ sort readdir($dh) ], ['.', '..'], "dir is empty: $dir"); | |||||||||||||||||||
| 204 | } | ||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | 92 | ▶ | sub file_meta { | ||||||||||||||||||
|
Subroutine
file_meta: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||
| 207 | 92 | my $path = shift; | |||||||||||||||||||
| 208 | 92 | my $st = File::stat::lstat($path); | |||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | 92 | my $meta = {}; | |||||||||||||||||||
| 211 | 92 | ▶ | $meta->{size} = $st->size unless -d $path; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 212 | 92 | ▶ | $meta->{is_file} = 1 if -f $path; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 213 | 92 | ▶ | $meta->{is_link} = 1 if -l $path; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 214 | 92 | ▶ | if ($meta->{is_link}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 215 | 0 | $meta->{link} = readlink $path; | |||||||||||||||||||
| 216 | } else { | ||||||||||||||||||||
| 217 | # we ignore these for links, since Linux doesn't let us restore anyway, | ||||||||||||||||||||
| 218 | # as Linux as no lutimes(2) syscall, as of Linux 2.6.16 at least | ||||||||||||||||||||
| 219 | 92 | $meta->{atime} = $st->atime if 0; # TODO: make tests work with atimes | |||||||||||||||||||
| 220 | 92 | $meta->{mtime} = $st->mtime; | |||||||||||||||||||
| 221 | 92 | $meta->{mode} = sprintf('%#o', $st->mode & 0777); | |||||||||||||||||||
| 222 | } | ||||||||||||||||||||
| 223 | |||||||||||||||||||||
| 224 | # the gpg tests open/close the rings in the root, so | ||||||||||||||||||||
| 225 | # mtimes get bumped around or something. the proper fix | ||||||||||||||||||||
| 226 | # is too ugly for what it's worth, so let's just ignore | ||||||||||||||||||||
| 227 | # the mtime of top-level | ||||||||||||||||||||
| 228 | 92 | ▶ | delete $meta->{mtime} if $path eq "."; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 229 | |||||||||||||||||||||
| 230 | 92 | return $meta; | |||||||||||||||||||
| 231 | } | ||||||||||||||||||||
| 232 | |||||||||||||||||||||
| 233 | # given a directory, returns a hashref of its contentn | ||||||||||||||||||||
| 234 | 8 | ▶ | sub dir_structure { | ||||||||||||||||||
|
Subroutine
dir_structure: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||
| 235 | 8 | my $dir = shift; | |||||||||||||||||||
| 236 | 8 | my %files; # "filename" -> {metadata => ...} | |||||||||||||||||||
| 237 | 8 | my $cwd = getcwd; | |||||||||||||||||||
| 238 | 8 | ▶ | chdir($dir) or die "Failed to chdir to $dir"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | find({ | ||||||||||||||||||||
| 241 | no_chdir => 1, | ||||||||||||||||||||
| 242 | 18 | ▶ | preprocess => sub { return sort @_ }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 243 | 88 | ▶ | wanted => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 244 | 88 | my $path = $_; | |||||||||||||||||||
| 245 | 88 | $files{$path} = file_meta($path); | |||||||||||||||||||
| 246 | }, | ||||||||||||||||||||
| 247 | 8 | }, "."); | |||||||||||||||||||
| 248 | |||||||||||||||||||||
| 249 | 8 | ▶ | chdir($cwd) or die "Failed to chdir back to $cwd"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 250 | 8 | return \%files; | |||||||||||||||||||
| 251 | } | ||||||||||||||||||||
| 252 | |||||||||||||||||||||
| 253 | # add a random number of orphan chunks to $target | ||||||||||||||||||||
| 254 | 1 | ▶ | sub add_orphan_chunks { | ||||||||||||||||||
|
Subroutine
add_orphan_chunks: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 255 | 1 | my ($root, $target, $orphan_chunks_count) = @_; | |||||||||||||||||||
| 256 | |||||||||||||||||||||
| 257 | 1 | for (1..$orphan_chunks_count) { | |||||||||||||||||||
| 258 | # HACK: to avoid worse hacks, we need a pchunk to store an orphan chunk. | ||||||||||||||||||||
| 259 | # We use small segments of 'pubring-test.gpg' so that they are different | ||||||||||||||||||||
| 260 | # than all other chunks | ||||||||||||||||||||
| 261 | 9 | my $pchunk = Brackup::PositionedChunk->new( | |||||||||||||||||||
| 262 | file => Brackup::File->new(root => $root, | ||||||||||||||||||||
| 263 | path => 'pubring-test.gpg'), | ||||||||||||||||||||
| 264 | offset => $_ * 10, | ||||||||||||||||||||
| 265 | length => 10, | ||||||||||||||||||||
| 266 | ); | ||||||||||||||||||||
| 267 | |||||||||||||||||||||
| 268 | # no encryption, copy raw data and store schunk | ||||||||||||||||||||
| 269 | 9 | my $schunk = Brackup::StoredChunk->new($pchunk); | |||||||||||||||||||
| 270 | # $schunk->copy_raw_data; | ||||||||||||||||||||
| 271 | 9 | $target->store_chunk($schunk); | |||||||||||||||||||
| 272 | } | ||||||||||||||||||||
| 273 | } | ||||||||||||||||||||
| 274 | |||||||||||||||||||||
| 275 | |||||||||||||||||||||
| 276 | 12 | 1; | |||||||||||||||||||
| 277 | |||||||||||||||||||||
| 278 | # vim:et:sw=4 | ||||||||||||||||||||