3 # DO NOT EDIT - This file is being maintained by Chef
8 use Date::Calc qw(Today Add_Delta_Days Add_Delta_YMD Day_of_Week);
15 GetOptions("days=i" => \$days, "weeks=i" => \$weeks, "months=i" => \$months);
23 $prefix = "${prefix}-";
30 for my $day (0 .. $days - 1)
32 push(@dates, sprintf("%04d-%02d-%02d", Subtract_Delta_Days(Today(), $day)));
35 for my $week (0 .. $weeks - 1)
37 push(@dates, sprintf("%04d-%02d-%02d", Subtract_Delta_Days(Monday(), $week * 7)));
40 for my $month (0 .. $months - 1)
42 push(@dates, sprintf("%04d-%02d-%02d", Subtract_Delta_YMD(First_of_Month(), 0, $month, 0)));
45 my $dates = join("|", @dates);
46 my $match = qr/^\Q${prefix}\E\d{4}-\d{2}-\d{2}\./;
47 my $keep = qr/^\Q${prefix}\E(?:${dates})\./;
49 opendir(DIR, "$dir") || die "Can't open ${dir}: $!";
51 my @files = sort(grep(/$match/, readdir(DIR)));
59 # print "Expiring $file\n" if $file !~ $keep;
60 unlink("${dir}/${file}") if $file !~ $keep;
69 return Subtract_Delta_Days(@today, Day_of_Week(@today) - 1);
74 my($year,$month,$day) = Today();
76 return($year,$month,1);
79 sub Subtract_Delta_Days
86 return Add_Delta_Days($year, $month, $day, -$days);
89 sub Subtract_Delta_YMD
98 return Add_Delta_YMD($year, $month, $day, -$years, -$months, -$days);