bin/rrr-news

filter: Statementstmt 34.4% 20 / 58 Branchbran 8.3% 2 / 24 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 30.0% 27 / 90 CC 1 SCAR 0.0
CC
1
Cov
26%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/File/Rsync/Mirror/Recentfile/FakeBigFloat.pm ↑ Summary bin/rrr-update »
1 #!/usr/bin/perl
2  
3 =head1 NAME
4  
5 rrr-news - list files added to the dataset
6  
7 =head1 SYNOPSIS
8  
9 rrr-news [options]
10  
11 =head1 OPTIONS
12  
13 =over 8
14  
15 =cut
16  
17 1 my @opt = <<'=back' =~ /B<--(\S+)>/g;
18  
19 =item B<--after=s>
20  
21 List all new files after this point in time. The format of the
22 timestamp is the unix epoch in floating point notation as used by
23 recentfiles in general.
24  
25 =item B<--before=s>
26  
27 List all new files before this point in time. The format of the
28 timestamp is the unix epoch in floating point notation as used by
29 recentfiles in general.
30  
31 =item B<--contains_epoch=s>
32  
33 List this file if the epoch is in the collection. Implies --max=1. Can
34 be combined with the other contains_* options to form a logical AND.
35  
36 =item B<--contains_path=s>
37  
38 List this file if the path is in the collection. Implies --max=1. Can
39 be combined with the other contains_* options to form a logical AND.
40  
41 =item B<--contains_type=s>
42  
43 List this file if the type is in the collection. Implies --max=1. Can
44 be combined with the other contains_* options to form a logical AND.
45  
46 =item B<--dry-run!>
47  
48 (TBD) Do not really run the command, ...
49  
50 =item B<--help|h>
51  
52 Prints a brief message and exits.
53  
54 =item B<--local=s>
55  
56 Specifies a local principal file. Nothing is mirrored, the list is
57 constructed from local resources. Cannot be combined with the
58 C<--remote> option.
59  
60 =item B<--localroot=s>
61  
62 Specifies the local root directory. C<--remote> must also be specified
63 and mirroring is happening implicitly. If missing, a temporary
64 directory is created to hold the data before constructing the list
65 (but this is inefficient in case the program is called again later
66 because the temporary directory is not persistent).
67  
68 =item B<--max=i>
69  
70 Limit the list to at max this many items.
71  
72 =item B<--remote=s>
73  
74 Specifies the remote principal file in rsync notation. This implies
75 that the necessary remote files will be mirrored before constructing
76 the list.
77  
78 =item B<--rsync_options|rsync=s@>
79  
80 Multiple options in the form of key=value pairs. E.g.
81  
82 --rsync=compress=1 --rsync=links=1
83  
84 The options are passed to the underlying L<File::Rsync> objects.
85  
86 =item B<--skip-deletes!>
87  
88 Boolean. If true then delete events are skipped.
89  
90 =item B<--verbose|v+>
91  
92 More feedback.
93  
94 =back
95  
96 =head1 DESCRIPTION
97  
98 rersyncrecent is a project to get speedy rsync operation on large
99 trees over multiple hosts. It maintains a collection of files with
100 metadata (so called recentfiles) that represent adjacent overlapping
101 timespans of file change events.
102  
103 rrr-news extracts from the recentfiles the new files added or
104 modified. The remote-principal-file is the rsync-notation for the
105 remote recentfile. The second argument is the path to the local mirror
106 directory. If you omit the second argument, a temporary directory is
107 taken instead.
108  
109 =cut
110  
111  
112 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
113 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
114  
115 1 ▶use File::Rsync::Mirror::Recent;
Subroutine BEGIN: called CC=1 SCAR=0.0
116 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
117 1 ▶use Pod::Usage qw(pod2usage);
Subroutine BEGIN: called CC=1 SCAR=0.0
118  
119 1 our %Opt;
120 1 ▶GetOptions(\%Opt,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%main::Opt, @opt) or pod2usage(2) 1 0 1
121 @opt,
122 ) or pod2usage(2);
123  
124 1 ▶if ($Opt{help}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::Opt{"help"}) 1 0 1
125 1 pod2usage(0);
126 }
127  
128 0 ▶if (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) 0 0 0
129 0 pod2usage(2);
130 }
131  
132 0 ▶if ($Opt{'dry-run'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::Opt{"dry-run"}) 0 0 0
133 0 die "FIXME: not yet implemented";
134 }
135  
136 0 my @constr;
137 0 for my $opt (qw(local remote localroot)) {
138 0 ▶ if (defined $Opt{$opt}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $main::Opt{$opt}) 0 0 0
139 0 push @constr, $opt => $Opt{$opt};
140 }
141 }
142 0 my $rf = File::Rsync::Mirror::Recent->new
143 (
144 @constr,
145 # stupid, need no rsync options when running with -local!
146 rsync_options => {
147 compress => 1,
148 links => 1,
149 times => 1,
150 checksum => 1,
151 },
152 );
153 0 ▶if ($rf->remote) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rf->remote) { } 0 0 0
elsif ($rf->local) { } 0 0 0
154 0 ▶ unless ($rf->localroot) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rf->localroot) 0 0 0
155 0 require File::Temp;
156 0 my $ldir = File::Temp::tempdir(
157 "rrr-news-XXXXXX",
158 TMPDIR => 1,
159 );
160 0 $rf->localroot($ldir);
161 }
162 } elsif ($rf->local) {
163 } else {
164 0 die "need either --local option or both of --remote and --localroot";
165 }
166 0 for my $passthrough (
167 "locktimeout",
168 "verbose",
169 ) {
170 0 ▶ if (my $x = $Opt{$passthrough}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $main::Opt{$passthrough}) 0 0 0
171 0 $rf->$passthrough($x);
172 }
173 }
174 {
175 0 my %rsopt;
176 0 ▶ for my $rsopt (@{$Opt{rsync_options}||[]}) {
Condition0%0/2
$main::Opt{'rsync_options'} || []
l!l
00
MC/DC0%0/1
$main::Opt{'rsync_options'} || []
$main::Opt{'rsync_options'}
Truth table0%0/2
A
A= $main::Opt{'rsync_options'}
Aresult
11
00
177 0 my($key,$value) = $rsopt =~ /([^=]+)=(.+)/s;
178 0 $rsopt{$key} = $value;
179 }
180 0 $rf->rsync_options(\%rsopt);
181 }
182 0 my @nopt;
183 0 for my $opt (qw(after before max skip-deletes)) {
184 0 ▶ if (defined $Opt{$opt}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $main::Opt{$opt}) 0 0 0
185 0 push @nopt, $opt => $Opt{$opt}
186 }
187 }
188 0 my $contains;
189 0 for my $opt (qw(path epoch type)) {
190 0 ▶ if (defined $Opt{"contains_$opt"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $main::Opt{"contains_$opt"}) 0 0 0
191 0 $contains->{$opt} = $Opt{"contains_$opt"};
192 }
193 }
194 0 ▶if ($contains) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contains) 0 0 0
195 0 push @nopt, max => 1, contains => $contains;
196 }
197 print map {
198 sprintf
199 (
200 "%-20s %s\n",
201 scalar localtime($_->{epoch}),
202 $_->{path},
203 0 )} @{ $rf->news(@nopt) };
204  
205 __END__
« blib/lib/File/Rsync/Mirror/Recentfile/FakeBigFloat.pm ↑ Summary bin/rrr-update »