bin/archive-dir

changeset 477
eeafc178ddc4
parent 476
0938f35f78f9
child 485
a58682115510
equal deleted inserted replaced
476:0938f35f78f9 477:eeafc178ddc4
17 ], 17 ],
18 default => 'year', 18 default => 'year',
19 } 19 }
20 ], 20 ],
21 ['age|a=i' => "minimum age in days for archival", {default => 60}], 21 ['age|a=i' => "minimum age in days for archival", {default => 60}],
22 ['yes|y' => "actually move files"], 22 ['files|f' => "operate on plain files only"],
23 ['yes|y' => "actually move stuff"],
23 ['help|h' => "print usage message and exit", {shortcircuit => 1}], 24 ['help|h' => "print usage message and exit", {shortcircuit => 1}],
24 ); 25 );
25 print($usage->text), exit if $opt->help; 26 print($usage->text), exit if $opt->help;
26 27
27 archive_dir($opt, $_) for @ARGV; 28 archive_dir($opt, $_) for @ARGV;
35 my $destfmt = ($opt->subdir eq 'month') ? '%Y-%m' : '%Y'; 36 my $destfmt = ($opt->subdir eq 'month') ? '%Y-%m' : '%Y';
36 my $nowish = time; 37 my $nowish = time;
37 my $age = $opt->age * 24 * 60 * 60; 38 my $age = $opt->age * 24 * 60 * 60;
38 39
39 for my $child ($dir->children) { 40 for my $child ($dir->children) {
40 next if $child->is_dir && ($child eq $destdir || $child =~ /^(?:\d{4}|\d\d)$/); 41 next if $child->is_dir && (
42 $opt->files || $child eq $destdir || $child =~ /^(?:\d{4}|\d\d)$/
43 );
44 next if $opt->files && $child->basename =~ /^\./;
41 45
42 my $mtime = $child->stat->mtime; 46 my $mtime = $child->stat->mtime;
43 next unless ($nowish - $mtime) >= $age; 47 next unless ($nowish - $mtime) >= $age;
44 48
45 my $dest = $destdir->child(localtime($mtime)->strftime($destfmt)); 49 my $dest = $destdir->child(localtime($mtime)->strftime($destfmt));

mercurial