modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java | 39 +++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)
New commits: commit 16823b9934ea91e81e0b7102bd464a57875fe033 Author: John Mazzitelli mazz@redhat.com Date: Tue Dec 6 14:16:32 2011 -0500
[BZ 752550] remove old downloaded bundle files to help clean out the tmp directory
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java index d240606..561e4a1 100644 --- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java +++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java @@ -23,6 +23,7 @@ package org.rhq.core.pc.bundle;
import java.io.File; +import java.io.FileFilter; import java.io.FileOutputStream; import java.io.OutputStream; import java.util.HashMap; @@ -47,10 +48,10 @@ import org.rhq.core.domain.bundle.BundleDeploymentStatus; import org.rhq.core.domain.bundle.BundleDestination; import org.rhq.core.domain.bundle.BundleResourceDeployment; import org.rhq.core.domain.bundle.BundleResourceDeploymentHistory; +import org.rhq.core.domain.bundle.BundleResourceDeploymentHistory.Status; import org.rhq.core.domain.bundle.BundleType; import org.rhq.core.domain.bundle.BundleVersion; import org.rhq.core.domain.bundle.ResourceTypeBundleConfiguration; -import org.rhq.core.domain.bundle.BundleResourceDeploymentHistory.Status; import org.rhq.core.domain.bundle.ResourceTypeBundleConfiguration.BundleDestinationBaseDirectory; import org.rhq.core.domain.content.PackageVersion; import org.rhq.core.domain.resource.Resource; @@ -72,6 +73,7 @@ import org.rhq.core.pluginapi.bundle.BundleManagerProvider; import org.rhq.core.pluginapi.bundle.BundlePurgeResult; import org.rhq.core.util.MessageDigestGenerator; import org.rhq.core.util.exception.ThrowableUtil; +import org.rhq.core.util.file.FileUtil;
/** * Manages the bundle subsystem, which allows bundles of content to be installed. @@ -172,6 +174,12 @@ public class BundleManager extends AgentService implements BundleAgentService, B File bundleFilesDir = new File(pluginTmpDir, "bundle-versions/" + bundleDeployment.getBundleVersion().getId()); bundleFilesDir.mkdirs(); + + // clean up any old downloads we may have retrieved before. This helps clean out + // our temp directory so we don't unnecessarily fill up our file system with obsolete files + removeOldDownloadedBundleFiles(bundleFilesDir); + + // now download the bundle files we need for the current deployment Map<PackageVersion, File> downloadedFiles = downloadBundleFiles(resourceDeployment, bundleFilesDir);
@@ -311,6 +319,35 @@ public class BundleManager extends AgentService implements BundleAgentService, B }
/** + * Given a directory where the current deployment's bundle files will reside, this method will clear out + * any other files located in other peer directories. In other words, the given directory and all its + * subdirectories and child files are left untouched, but all files and directories found in peer + * directories are wiped. This helps clean out our temp directory so we don't fill up the file system + * with old downloaded files that we don't need anymore. See BZ 752550. + * + * @param currentBundleVersionFilesDir + */ + private void removeOldDownloadedBundleFiles(final File currentBundleVersionFilesDir) { + File parent = null; + try { + parent = currentBundleVersionFilesDir.getParentFile(); + File[] doomedFiles = parent.listFiles(new FileFilter() { + public boolean accept(File child) { + return !currentBundleVersionFilesDir.equals(child); + } + }); + for (File doomedFile : doomedFiles) { + FileUtil.purge(doomedFile, true); + } + } catch (Exception e) { + log.warn("Failed to clean up old downloaded bundle files in [" + + parent + + "]. You can ignore this but if the agent is asked to deploy a lot of bundles, the file system may fill up." + + " Cause: " + e); + } + } + + /** * Downloads the bundle's files into the bundle plugin's tmp directory and returns that tmp directory. * * @param resourceDeployment access to deployment information, including what bundle files need to be downloaded
rhq-commits@lists.fedorahosted.org