From 3226ce71cef10280e3827ac4429cc882f1ebac37 Mon Sep 17 00:00:00 2001 From: Andrew DeFaria Date: Mon, 5 Mar 2018 17:56:56 -0800 Subject: [PATCH] Updated cleantmp --- bin/cleantmp.pl | 21 +++++++++++++++------ etc/cleantmp.conf | 4 ++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/bin/cleantmp.pl b/bin/cleantmp.pl index ac26cc8..79c567a 100755 --- a/bin/cleantmp.pl +++ b/bin/cleantmp.pl @@ -64,7 +64,7 @@ use Getopt::Long; use Pod::Usage; use File::Monitor; use File::Spec; -use File::Path; +use File::Path qw/remove_tree/; use lib "$FindBin::Bin/../lib"; @@ -115,7 +115,11 @@ sub FileCreated { next if $createdFile =~ /^\./; # Skip all hidden files for my $pattern (loadConfig) { + debug "Processing pattern $pattern"; + if ($createdFile =~ /$pattern/) { + debug "Matched $createdFile to $pattern"; + if (-d "$opts{tmp}/$createdFile") { remove_tree ("$opts{tmp}/$createdFile", {error => \my $err}); @@ -130,13 +134,13 @@ sub FileCreated { } # if } # for } else { - $log->msg(scalar localtime . " $opts{tmp}/$createdFile removed"); + $log->msg("$opts{tmp}/$createdFile removed"); } # if } else { unless (unlink "$opts{tmp}/$createdFile") { $log->err("Unable to remove $opts{tmp}/$createdFile - $!"); } else { - $log->msg(scalar localtime . " $opts{tmp}/$createdFile removed"); + $log->msg("$opts{tmp}/$createdFile removed"); } # if } # if @@ -162,9 +166,14 @@ GetOptions ( 'sleep=i' ) or pod2usage; -$log = Logger->new(path => $opts{logpath}); +$log = Logger->new(path => $opts{logpath}, timestamped => 1); + +$log->msg("Starting $FindBin::Script"); -$log->msg(scalar localtime . ": Starting $FindBin::Script"); +# First run through whatever junk is in /tmp +for (glob "$opts{tmp}/*") { + FileCreated($_); +} # for my $monitor = File::Monitor->new; @@ -176,7 +185,7 @@ $monitor->watch({ set_debug if $DB::OUT; -EnterDaemonMode unless $DB::OUT; +EnterDaemonMode unless $DB::OUT or get_debug; while () { $monitor->scan; diff --git a/etc/cleantmp.conf b/etc/cleantmp.conf index 782f042..13e0d5c 100644 --- a/etc/cleantmp.conf +++ b/etc/cleantmp.conf @@ -20,3 +20,7 @@ clipboardcache.* userstorage.* .+.tmp \+~.* +evince-.* +qtsingleapp.* +mozilla_.* +MozillaMailnews -- 2.17.1