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);
21 for my $day (0 .. $days - 1)
23 push(@dates, sprintf("%04d-%02d-%02d", Subtract_Delta_Days(Today(), $day)));
26 for my $week (0 .. $weeks - 1)
28 push(@dates, sprintf("%04d-%02d-%02d", Subtract_Delta_Days(Monday(), $week * 7)));
31 for my $month (0 .. $months - 1)
33 push(@dates, sprintf("%04d-%02d-%02d", Subtract_Delta_YMD(First_of_Month(), 0, $month, 0)));
36 my $dates = join("|", @dates);
37 my $match = qr/^${prefix}-\d{4}-\d{2}-\d{2}\./;
38 my $keep = qr/^${prefix}-(?:${dates})\./;
40 opendir(DIR, "$dir") || die "Can't open ${dir}: $!";
42 while (my $file = readdir(DIR))
44 # print "Expiring $file\n" if $file =~ $match && $file !~ $keep;
45 unlink("${dir}/${file}") if $file =~ $match && $file !~ $keep;
56 return Subtract_Delta_Days(@today, Day_of_Week(@today) - 1);
61 my($year,$month,$day) = Today();
63 return($year,$month,1);
66 sub Subtract_Delta_Days
73 return Add_Delta_Days($year, $month, $day, -$days);
76 sub Subtract_Delta_YMD
85 return Add_Delta_YMD($year, $month, $day, -$years, -$months, -$days);