up the version with perl-reversion
[rersyncrecent.git] / bin / rrr-dirtyupdate
blob19310d7b92fe4eb07a60d3d6e645ed6d0eb45f3f
1 #!/usr/bin/perl -- -*- mode: cperl -*-
3 =head1 NAME
5 rrr-dirtyupdate - add a file with an old timestamp to the dataset
7 =head1 SYNOPSIS
9 rrr-dirtyupdate [options] principalfile file [epoch]
11 rrr-dirtyupdate --force principalfile
13 =head1 OPTIONS
15 =over 8
17 =cut
19 my @opt = <<'=back' =~ /B<--(\S+)>/g;
21 =item B<--delete>
23 Inject a delete event. If the epoch argument is missing, find the
24 according file event and set epoch to that epoch plus 1.
26 =item B<--force|f>
28 Force this run even without any arguments. E.g. just for the side
29 effect of running an aggregate call.
31 =item B<--help|h>
33 Prints a brief message and exists.
35 =item B<--verbose|v+>
37 More feedback.
39 =back
41 =head1 DESCRIPTION
43 When you later discover missing files...
45 The principalfile argument is the path to local principal recentfile.
47 The file argument is a relative path calculated from the localroot
48 directory of the recentfile object.
50 If the epoch argument is missing it is calculated from the
51 modification time of the file.
53 =head1 BUGS
55 This is slow: it calls aggregate twice with force which took 2 x 10-20 seconds on PAUSE.
57 =cut
60 use strict;
61 use warnings;
63 use File::Find qw(find);
64 use lib "/home/k/sources/rersyncrecent/lib";
65 use File::Rsync::Mirror::Recent;
66 use File::Spec;
67 use Getopt::Long;
68 use Pod::Usage qw(pod2usage);
70 our %Opt;
71 GetOptions(\%Opt,
72 @opt,
73 ) or pod2usage(1);
75 if ($Opt{help}) {
76 pod2usage(0);
79 my $aggregate_only = 0;
80 if (@ARGV == 1) {
81 if ($Opt{force}) {
82 $aggregate_only=1;
83 } else {
84 pod2usage(1);
86 } elsif (@ARGV >= 3) {
87 pod2usage(1);
90 my($principal,$file,$epoch) = @ARGV;
91 my $recc = File::Rsync::Mirror::Recent->new
92 (local => $principal);
93 my($rf) = $recc->principal_recentfile;
94 my $abs_file = File::Spec->catfile($rf->localroot,$file);
96 unless ($aggregate_only) {
97 unless (defined $epoch) {
98 if ($Opt{delete}) {
99 my $news = $recc->news(contains => { path => $file });
100 if (@$news) {
101 print "Found file:\n", YAML::Syck::Dump $news;
102 $epoch = $news->[0]{epoch} + 1;
103 } else {
104 die "didn't find '$file' in this recentfile collection";
106 } else {
107 my(@stat) = stat $abs_file or die "Could not stat '$abs_file': $!";
108 $epoch = $stat[9];
111 my $type = $Opt{delete} ? "delete" : "add";
112 $rf->update($abs_file,$type,$epoch);
114 warn localtime()." starting first aggregate\n";
115 $rf->aggregate(force => 1);
116 warn localtime()." starting second aggregate\n";
117 $rf->aggregate(force => 1);
118 warn localtime()." finished\n";
121 __END__
124 # Local Variables:
125 # mode: cperl
126 # coding: utf-8
127 # cperl-indent-level: 4
128 # End: