From ffadb3beb1b80943860f49ef2ef88bf294235d3f Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 19 Aug 2020 21:40:21 +0100 Subject: [PATCH] expire-8601: wip new version Signed-off-by: Ian Jackson --- scripts/expire-iso8601.new | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/scripts/expire-iso8601.new b/scripts/expire-iso8601.new index bcf4ec9..6c8ffd9 100755 --- a/scripts/expire-iso8601.new +++ b/scripts/expire-iso8601.new @@ -44,8 +44,11 @@ exit status: 16 catastrophic failure END +use POSIX; use Carp; -use DateTime::Format::RFC3339; +use Data::Dumper; +use Date::Parse; +use DateTime::Format::Strptime; our @files; our $rm = 1; @@ -60,17 +63,25 @@ sub badusage ($) { } sub scan () { - my $parser = DateTime::Format::RFC3339->new; - +# my $strp = DateTime::Format::Strptime->new(); foreach my $f (<[0-9]*>) { if ($f !~ m/^ \d\d\d\d - \d\d - \d\d (?: T \d\d \: \d\d (?: \: \d\d )? (?: [-+] \d{1,2} \:? \d\d )? )? /x) { print STDERR "ignoring $f\n"; } - $!=0; $?=0; my $t = `date -d '$&' +%s`; - die "date(!) failed on $&: $? $!" if $! || $?; - chomp $t or confess; + my @t = Date::Parse::strptime($f); + @t = map { $_ // 0 } @t; + my $t = mktime @t; +# m +# my $t = $strp->parse_datetime($f); +# $t = $t->epoch(); +# my @t = Date::Parse::strptime($f); +#print STDERR Dumper(\@t); +# my $t = mktime(@t); +# $!=0; $?=0; my $t = `date -d '$&' +%s`; +# die "date(!) failed on $&: $? $!" if $! || $?; +# chomp $t or confess; push @files, { F => $f, T => $t, U => [] }; } } @@ -86,6 +97,8 @@ sub precomp () { my $newest_t = $files[0]{T}; $_->{A} = ($newest_t - $_->{T}) / $unit foreach @files; $slop /= $unit; + +# print DEBUG Dumper(\@files, \@intervals); } sub flag ($) { @@ -96,8 +109,11 @@ sub flag ($) { my $start_age = ($n+1) * $d; my $i = 0; + print DEBUG "FLAG $spec\n"; + # find $i, the youngest which is at least $number x $interval for (;;) { + print DEBUG "i #$i $files[$i]{A}\n"; last if $files[$i]{A} > $start_age; if ($i == $#files) { print STDERR "insufficient for $spec\n"; @@ -115,6 +131,7 @@ sub flag ($) { last if $j < 0; last if $files[$j]; my $dt = $files[$i]{A} - $files[$j]{A}; + print DEBUG "j #$j $files[$j]{A} dt=$dt\n"; last if $dt >= $d - $slop; } last if $j < 0; @@ -139,6 +156,8 @@ sub implement () { } } +open DEBUG, ">/dev/null" or die $!; + while (@ARGV && $ARGV[0] =~ m/^-/) { $_ = shift @ARGV; last if $_ eq '-' || $_ eq '--'; @@ -146,6 +165,7 @@ while (@ARGV && $ARGV[0] =~ m/^-/) { while (m/^-./) { if (s/^-n/-/) { $rm=0; } elsif (s/-r/-/) { $recurse=1; } + elsif (s/-D/-/) { open DEBUG, ">&STDERR" or die $!; } elsif (s/-u(\d+)$//) { $unit=$1; } elsif (s/-s(\d+)$//) { $slop=$1; } else { badusage "unknown short option $_" } -- 2.30.2