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/^${prefix}\d{4}-\d{2}-\d{2}\./;
47 my $keep = qr/^${prefix}(?:${dates})\./;
49 opendir(DIR, "$dir") || die "Can't open ${dir}: $!";
51 while (my $file = readdir(DIR))
53 # print "Expiring $file\n" if $file =~ $match && $file !~ $keep;
54 unlink("${dir}/${file}") if $file =~ $match && $file !~ $keep;
65 return Subtract_Delta_Days(@today, Day_of_Week(@today) - 1);
70 my($year,$month,$day) = Today();
72 return($year,$month,1);
75 sub Subtract_Delta_Days
82 return Add_Delta_Days($year, $month, $day, -$days);
85 sub Subtract_Delta_YMD
94 return Add_Delta_YMD($year, $month, $day, -$years, -$months, -$days);