s/contains_path/contains/ as the principal of least surprise
[rersyncrecent.git] / bin / rrr-dirtyupdate
blob67d6309490f4967938010e483728144934f19abe
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 must be an existing file.
49 If the epoch argument is missing it is calculated from the
50 modification time of the file.
52 =head1 BUGS
54 This is slow: it calls aggregate twice with force which took 2 x 10-20 seconds on PAUSE.
56 =cut
59 use strict;
60 use warnings;
62 use File::Find qw(find);
63 use lib "/home/k/sources/rersyncrecent/lib";
64 use File::Rsync::Mirror::Recent;
65 use Getopt::Long;
66 use Pod::Usage qw(pod2usage);
68 our %Opt;
69 GetOptions(\%Opt,
70 @opt,
71 ) or pod2usage(1);
73 if ($Opt{help}) {
74 pod2usage(0);
77 my $aggregate_only = 0;
78 if (@ARGV == 1) {
79 if ($Opt{force}) {
80 $aggregate_only=1;
81 } else {
82 pod2usage(1);
84 } elsif (@ARGV >= 3) {
85 pod2usage(1);
88 my($principal,$file,$epoch) = @ARGV;
89 my $recc = File::Rsync::Mirror::Recent->new
90 (local => $principal);
91 my($rf) = $recc->principal_recentfile;
93 unless ($aggregate_only) {
94 unless (defined $epoch) {
95 if ($Opt{delete}) {
96 warn "not yet implemented???";
97 my $news = $recc->news(contains => $file);
98 if ($news) {
99 print YAML::Syck::Dump $news;
101 die "FIXME";
102 } else {
103 my(@stat) = stat $file or die "Could not stat '$file': $!";
104 $epoch = $stat[9];
107 my $type = $Opt{delete} ? "delete" : "add";
108 $rf->update($file,$type,$epoch);
110 warn localtime()." starting first aggregate\n";
111 $rf->aggregate(force => 1);
112 warn localtime()." starting second aggregate\n";
113 $rf->aggregate(force => 1);
114 warn localtime()." finished\n";
117 __END__
120 # Local Variables:
121 # mode: cperl
122 # coding: utf-8
123 # cperl-indent-level: 4
124 # End: