modules/core/util/src/main/java/org/rhq/core/util/updater/Deployer.java | 4 modules/core/util/src/test/java/org/rhq/core/util/updater/SimpleDeployerTest.java | 46 +++++++--- 2 files changed, 38 insertions(+), 12 deletions(-)
New commits: commit 657f2f242c2193173b8e68b6cdb34f04f2057d43 Author: John Mazzitelli mazz@redhat.com Date: Fri Jan 27 16:56:27 2012 -0500
[BZ 785268] fix the case where you do a clean deploy but a file was edited (where the file content didn't change from bundle v1 to bundle v2)
diff --git a/modules/core/util/src/main/java/org/rhq/core/util/updater/Deployer.java b/modules/core/util/src/main/java/org/rhq/core/util/updater/Deployer.java index 40ce727..602df4c 100644 --- a/modules/core/util/src/main/java/org/rhq/core/util/updater/Deployer.java +++ b/modules/core/util/src/main/java/org/rhq/core/util/updater/Deployer.java @@ -422,9 +422,11 @@ public class Deployer { // that a file is different from the deployment distribution. // If the new is different from the original and if the new is different than the current, we need to backup the // current because we will be overwriting the current file with the new. + // Note that if we were told to "clean", we never leave files alone (since everything must be cleaned) but + // we will backup the touched file that is being removed String changedFileHashcode = changed.getValue(); String originalFileHashcode = original.get(changedFilePath); - if (newHashcode.equals(originalFileHashcode)) { + if (newHashcode.equals(originalFileHashcode) && !clean) { currentFilesToLeaveAlone.put(changedFilePath, originalFileHashcode); } else if (!newHashcode.equals(changedFileHashcode)) { currentFilesToBackup.add(changedFilePath); diff --git a/modules/core/util/src/test/java/org/rhq/core/util/updater/SimpleDeployerTest.java b/modules/core/util/src/test/java/org/rhq/core/util/updater/SimpleDeployerTest.java index d8a355f..8a222a4 100644 --- a/modules/core/util/src/test/java/org/rhq/core/util/updater/SimpleDeployerTest.java +++ b/modules/core/util/src/test/java/org/rhq/core/util/updater/SimpleDeployerTest.java @@ -118,7 +118,11 @@ public class SimpleDeployerTest { }
public void testX_Y_X() throws Exception { - baseX_Y_X(false); + baseX_Y_X(false, false); + } + + public void testX_Y_X_Clean() throws Exception { + baseX_Y_X(false, true); }
public void testX_Y_Y() throws Exception { @@ -174,7 +178,11 @@ public class SimpleDeployerTest { }
public void testX_Y_X_DryRun() throws Exception { - baseX_Y_X(true); + baseX_Y_X(true, false); + } + + public void testX_Y_X_DryRun_Clean() throws Exception { + baseX_Y_X(true, true); }
public void testX_Y_Y_DryRun() throws Exception { @@ -414,7 +422,7 @@ public class SimpleDeployerTest { } }
- private void baseX_Y_X(boolean dryRun) throws Exception { + private void baseX_Y_X(boolean dryRun, boolean clean) throws Exception { String newContent = "testX_Y_X"; String newHashcode = MessageDigestGenerator.getDigestString(newContent); writeFile(newContent, this.currentFile); @@ -423,11 +431,7 @@ public class SimpleDeployerTest { null, null, true, null); Deployer deployer = new Deployer(dd); FileHashcodeMap newFileHashcodeMap; - if (dryRun) { - newFileHashcodeMap = deployer.dryRun(this.diff); - } else { - newFileHashcodeMap = deployer.deploy(this.diff); - } + newFileHashcodeMap = deployer.deploy(this.diff, clean, dryRun);
// very important to understand this - even though the current file is changed, the hashcode // stored in the map and the metadata directory is the ORIGINAL hashcode. This is to make it @@ -439,17 +443,37 @@ public class SimpleDeployerTest {
assert newFileHashcodeMap.equals(this.originalFileHashcodeMap); String[] contentHash = getOriginalFilenameContentHashcode(); - assert contentHash[0].equals(newContent); - assert contentHash[1].equals(newHashcode); + + // if we are cleaning, then the old content is blown away anyway and the original is replaced + // (but not if this is a dryRun - dryRun always means the changed/new content remains) + if (clean && !dryRun) { + assert contentHash[0].equals(originalContent); + assert contentHash[1].equals(originalHashcode); + } else { + assert contentHash[0].equals(newContent); + assert contentHash[1].equals(newHashcode); + }
// note nothing changed - our current file remains as is assert this.diff.getAddedFiles().isEmpty() : this.diff; assert this.diff.getDeletedFiles().isEmpty() : this.diff; assert this.diff.getChangedFiles().isEmpty() : this.diff; - assert this.diff.getBackedUpFiles().isEmpty() : this.diff; + if (clean) { + assert this.diff.getBackedUpFiles().size() == 1 : this.diff; + assert this.diff.getBackedUpFiles().containsKey(originalFileName) : this.diff; + File backupFile = new File(this.diff.getBackedUpFiles().get(originalFileName)); + if (dryRun) { + assert !backupFile.exists() : "dry run should not create backup"; + } else { + assert readFile(backupFile).equals(newContent) : "did not backup the correct file?"; + } + } else { + assert this.diff.getBackedUpFiles().isEmpty() : this.diff; + } assert this.diff.getIgnoredFiles().isEmpty() : this.diff; assert this.diff.getRealizedFiles().isEmpty() : this.diff; assert this.diff.getErrors().isEmpty() : this.diff; + assert this.diff.wasCleaned() == clean : this.diff;
if (dryRun) { assert this.metadata.getCurrentDeploymentProperties().equals(originalDeployProps);
rhq-commits@lists.fedorahosted.org