[Rt-commit] r6032 - RT-Extension-TicketAging/sbin
ruz at bestpractical.com
ruz at bestpractical.com
Mon Sep 25 19:16:36 EDT 2006
Author: ruz
Date: Mon Sep 25 19:16:36 2006
New Revision: 6032
Modified:
RT-Extension-TicketAging/sbin/rt-aging
Log:
* --prune-backups option
Modified: RT-Extension-TicketAging/sbin/rt-aging
==============================================================================
--- RT-Extension-TicketAging/sbin/rt-aging (original)
+++ RT-Extension-TicketAging/sbin/rt-aging Mon Sep 25 19:16:36 2006
@@ -146,8 +146,56 @@
}
sub prune_backups {
+ my %arg = (OlderThan => 0, @_);
+
+ require File::Spec;
+ my $name = RT->Config->Get('TicketAgingFilenameTemplate');
+ my $base;
+ unless ( $name ) {
+ require RT::Shredder;
+ $base = RT::Shredder->StoragePath
+ }
+ elsif ( !File::Spec->file_name_is_absolute( $name ) ) {
+ require RT::Shredder;
+ $name = File::Spec->catfile(RT::Shredder->StoragePath, $name);
+ }
+ $base ||= File::Spec->catpath( (File::Spec->splitpath( $name ))[0,1] );
+ $base = File::Spec->catfile( $base, '*' );
+ $RT::Logger->debug(loc("Scanning files in '[_1]'...", $base));
+
+ require RT::Date;
+ my $date = RT::Date->new( $RT::SystemUser );
+ $date->Unix( time - $arg{'OlderThan'}*24*60*60 );
+ $RT::Logger->debug(loc("Looking for files older than [_1]...", $date->AsString));
+
+ my $mtime = $date->Unix;
+ my @files = grep { (stat $_)[9] < $mtime && -f _ } glob $base;
+ unless ( @files ) {
+ $RT::Logger->debug(loc("No files"));
+ exit;
+ }
+ exit unless prompt_yN( loc("Do you want delete [_1] file(s)", scalar @files) );
+
+ foreach my $file( @files ) {
+ $RT::Logger->debug( $file );
+ unlink $file or $RT::Logger->error(loc("Couldn't delete file '[_1]': [_2]", $file, $!));
+ }
+ exit;
+}
+
+
+sub prompt_yN
+{
+ my $text = shift;
+ print "$text [y/N] ";
+ unless( <STDIN> =~ /^(?:y|yes)$/i ) {
+ return 0;
+ }
+ return 1;
}
+
+
__END__
=head1 NAME
More information about the Rt-commit
mailing list