# HG changeset patch # User Meredith Howard # Date 1493342998 14400 # Node ID 0bd45054802ed7270ed5cae27ed8769d6d76c59c # Parent e34f183fbd55fd0688bbe4e899430f75ac678de3 sort and format plan before working diff --git a/bin/archive-dir b/bin/archive-dir --- a/bin/archive-dir +++ b/bin/archive-dir @@ -1,5 +1,5 @@ #!/usr/bin/env perl - +use 5.014; use warnings; use strict; use Time::Piece; @@ -37,6 +37,8 @@ sub archive_dir { my $nowish = time; my $age = $opt->age * 24 * 60 * 60; + my @work; + for my $child ($dir->children) { next if $child->is_dir && ( $opt->files || $child eq $destdir || $child =~ /^(?:\d{4}|\d\d)$/ @@ -47,8 +49,17 @@ sub archive_dir { next unless ($nowish - $mtime) >= $age; my $dest = $destdir->child(localtime($mtime)->strftime($destfmt)); + push @work, [$dest, $child]; + } - print "$dest \t $child\n"; + my $lastdest = ''; + for my $work (sort {$a->[0] cmp $b->[0]} @work) { + my ($dest, $child) = @$work; + + say $lastdest = $dest + if $dest ne $lastdest; + + say "\t$child"; next unless $opt->yes; $dest->mkpath;