bin/rrr-update

filter: Statementstmt 43.3% 26 / 60 Branchbran 9.0% 2 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 39.3% 35 / 89 CC 1 SCAR 0.0
CC
1
Cov
34%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« bin/rrr-news ↑ Summary bin/rrr-client »
1 #!/usr/bin/perl
2  
3 =head1 NAME
4  
5 rrr-update - add a file to/delete a file from the dataset
6  
7 =head1 SYNOPSIS
8  
9 rrr-update [options] principalfile file
10  
11 =head1 OPTIONS
12  
13 =over 8
14  
15 =cut
16  
17 1 my @opt = <<'=back' =~ /B<--(\S+)>/g;
18  
19 =item B<--add>
20  
21 Inject a 'new' event.
22  
23 =item B<--delete>
24  
25 Inject a 'delete' event.
26  
27 =item B<--dry-run|n>
28  
29 Does nothing, only prints what it would do.
30  
31 =item B<--epoch=s>
32  
33 Set the epoch of the file to this value. Normally epoch is set to
34 current time as a floating point value. This option can be used to
35 inject old events that have been forgotten somehow. Triggers setting
36 of the dirtymark of the whole dataset which means all slaves are
37 forced to restart their mirroring activity.
38  
39 Be aware that this is not only costly to downstream servers, it is
40 also slow: it calls aggregate twice with force.
41  
42 =item B<--help|h>
43  
44 Prints a brief message and exits.
45  
46 =item B<--verbose|v+>
47  
48 More feedback.
49  
50 =back
51  
52 =head1 DESCRIPTION
53  
54 When you later discover missing files...
55  
56 The principalfile argument is the path to local principal recentfile.
57  
58 The file argument is a relative path calculated from the localroot
59 directory of the recentfile object.
60  
61  
62 =cut
63  
64  
65 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68 1 ▶use File::Find qw(find);
Subroutine BEGIN: called CC=1 SCAR=0.0
69 1 ▶use File::Rsync::Mirror::Recent;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 1 ▶use Pod::Usage qw(pod2usage);
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74 1 our %Opt;
75 1 ▶GetOptions(\%Opt,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%main::Opt, @opt) or pod2usage(1) 1 0 1
76 @opt,
77 ) or pod2usage(1);
78  
79 1 ▶if ($Opt{help}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::Opt{"help"}) 1 0 1
80 1 pod2usage(0);
81 }
82  
83 0 ▶if (@ARGV != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV != 2) 0 0 0
84 0 pod2usage(1);
85 }
86  
87 0 my($principal,$file) = @ARGV;
88 0 my $recc = File::Rsync::Mirror::Recent->new
89 (local => $principal);
90 0 my($rf) = $recc->principal_recentfile;
91 0 my($abs_file,$rel_file);
92 0 ▶if (File::Spec->file_name_is_absolute($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if ('File::Spec'->file_name_is_absolute($file)) { } 0 0 0
93 0 $rel_file = substr($file,length $rf->localroot);
94 0 $abs_file = $file;
95 } else {
96 0 $rel_file = $file;
97 0 $abs_file = File::Spec->catfile($rf->localroot,$file);
98 }
99  
100 0 my $type = "new";
101 0 ▶if ($Opt{delete}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($main::Opt{'delete'}) { } 0 0 0
elsif ($main::Opt{'add'}) { } 0 0 0
102 0 my $news = $recc->news(contains => { path => $rel_file });
103 0 ▶ if (@$news) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$news) { } 0 0 0
104 0 warn "Found file:\n".YAML::Syck::Dump $news;
105 } else {
106 0 die "Didn't find '$file' in this recentfile collection, giving up.";
107 }
108 0 $type = "delete";
109 } elsif ($Opt{add}) {
110 0 my $news = $recc->news(contains => { path => $rel_file });
111 0 ▶ if (@$news) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$news) 0 0 0
112 0 warn "Info: found file in index:\n".YAML::Syck::Dump $news;
113 }
114 0 $type = "new";
115 }
116  
117 0 my $epoch = $Opt{epoch};
118 0 ▶if (defined $epoch) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $epoch) { } 0 0 0
119 0 ▶ if ($Opt{"dry-run"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::Opt{'dry-run'}) { } 0 0 0
120 0 warn sprintf "Would call update on directory %s with args abs_file[%s], type[%s], epoch[%s] and then aggregate with force twice.\n",
121 $rf->localroot, $abs_file, $type, $epoch;
122 } else {
123 0 $rf->update($abs_file,$type,$epoch);
124 0 warn localtime()." starting first aggregate\n";
125 0 $rf->aggregate(force => 1);
126 0 warn localtime()." starting second aggregate\n";
127 0 $rf->aggregate(force => 1);
128 }
129 } else {
130 0 ▶ if ($Opt{"dry-run"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::Opt{'dry-run'}) { } 0 0 0
131 0 warn sprintf "Would call update on directory %s with args abs_file[%s], type[%s].\n",
132 $rf->localroot, $abs_file, $type, $epoch;
133 } else {
134 0 $rf->update($abs_file,$type);
135 }
136 }
137  
138  
139 __END__
« bin/rrr-news ↑ Summary bin/rrr-client »