From 1f05c08cd8694d167c24cddbb0468d9b71ce165c Mon Sep 17 00:00:00 2001 From: ramonn Date: Wed, 21 Jul 2010 11:32:08 +0000 Subject: [PATCH] 2010-07-21 Ramon Novoa * pandora_agent: Delete unused collections. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3048 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_agents/unix/ChangeLog | 4 ++++ pandora_agents/unix/pandora_agent | 38 +++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/pandora_agents/unix/ChangeLog b/pandora_agents/unix/ChangeLog index 12092255d5..e3ea81bd0e 100644 --- a/pandora_agents/unix/ChangeLog +++ b/pandora_agents/unix/ChangeLog @@ -1,3 +1,7 @@ +2010-07-21 Ramon Novoa + + * pandora_agent: Delete unused collections. + 2010-07-20 Ramon Novoa * pandora_agent_installer: Fixed some directories and permissions. diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 48c1d6d678..519d4e1e2c 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -503,10 +503,23 @@ sub check_remote_config () { } ################################################################################ -# Check and download collections. +# Delete old collections and download new collections. ################################################################################ sub check_collections () { + # Delete old collections + opendir (DIR, "$ConfDir/collections") || return; + while (defined (my $file_name = readdir(DIR))) { + next if ($file_name eq '.' || $file_name eq '..'); + + # Do not delete md5 files associated to a collection + $file_name =~ s/\.md5$//; + + rmrf ("$ConfDir/collections/$file_name") unless defined ($Collections{$file_name}); + } + closedir (DIR); + + # Download new collections while (my ($collection, $in_path) = each (%Collections)) { my $collection_file = $collection . ".zip"; my $collection_md5_file = $collection . ".md5"; @@ -541,7 +554,8 @@ sub check_collections () { # Download and unzip next unless (recv_file ($collection_file) == 0); - `rm -rf "$ConfDir/collections/$collection" 2>/dev/null && unzip -d "$ConfDir/collections/$collection" "$Conf{'temporal'}/$collection_file" 2>/dev/null`; + rmrf ("$ConfDir/collections/$collection"); + `unzip -d "$ConfDir/collections/$collection" "$Conf{'temporal'}/$collection_file" 2>/dev/null`; unlink ("$Conf{'temporal'}/$collection_file"); } } @@ -1060,6 +1074,26 @@ sub check_module_cron ($) { return 1; } +################################################################################ +# Recursively delete files and directories. +################################################################################ +sub rmrf { + my ($path) = @_; + local *DIR; + + if (-d $path) { + opendir (DIR, $path) || return; + while (defined (my $file_name = readdir(DIR))) { + next if ($file_name eq '.' || $file_name eq '..'); + rmrf ("$path/$file_name"); + } + closedir (DIR); + rmdir ($path); + } else { + unlink ($path); + } +} + ################################################################################ # Main. ################################################################################