5 rrr-init - set up RECENT files for a directory tree
9 rrr-init [options] directory
17 my @opt = <<'=back' =~ /B<--(\S+)>/g;
19 =item B<--aggregator=s>
21 Comma separated list of aggregator specifications, e.g.
23 --aggregator=1h,6h,1d,1W,1M,1Q,1Y,Z
25 Defaults to C<1h,1d,1M,1Y,Z>
29 Forces an overwrite of an already existing recentfile in the target
34 Prints a brief message and exists.
44 Walk through a tree and fill all files into initial recentfiles.
53 use lib
"/home/k/sources/rersyncrecent/lib";
54 use File
::Rsync
::Mirror
::Recent
;
55 use File
::Rsync
::Mirror
::Recentfile
;
58 use Pod
::Usage
qw(pod2usage);
59 use Time
::HiRes
qw(time);
75 # speed up fail on missing module:
76 require Time
::Progress
;
80 my $aggregator_string = $Opt{aggregator
} || "1h,1d,1M,1Y,Z";
81 my @aggregator = split /\s*,\s*/, $aggregator_string;
82 my $localroot = File
::Spec
->rel2abs($rootdir);
83 my $rfconstructor = sub {
84 return File
::Rsync
::Mirror
::Recentfile
->new
86 aggregator
=> \
@aggregator,
87 interval
=> $aggregator[0],
88 localroot
=> $localroot,
89 verbose
=> $Opt{verbose
},
92 my $rf = $rfconstructor->();
93 my $rfilename = File
::Spec
->catfile
101 unlink $rfilename or die "Could not unlink '%s': %s", $rfilename, $!;
102 $rf = $rfconstructor->();
104 die sprintf "Alert: Found an already existing file '%s'. Won't overwrite. Either use --force or remove the file before calling me again", $rfilename;
107 warn "Debug: rfilename[$rfilename]";
111 foreach my $file ( File
::Find
::Rule
->new->file->in($rootdir) ) {
112 my $path = File
::Spec
->rel2abs($file);
113 my $epoch = (stat $path)[9];
114 push @batch, {path
=>$path,type
=>"new",epoch
=>$epoch};
118 warn sprintf "Found %d files to register in %.6f s. Writing to %s\n", scalar @batch, $t[1]-$t[0], $rfilename;
120 $rf->batch_update(\
@batch);
123 warn sprintf "Registered %d files in %.6f s\n", scalar @batch, $t[2]-$t[1];
132 # cperl-indent-level: 4