Skip to content

Commit 211311c

Browse files
Emanuel Muckenhuberbstansberry
Emanuel Muckenhuber
authored andcommittedFeb 26, 2014
[WFLY-3012] don't report a conflict for empty directories
1 parent 8d4696d commit 211311c

File tree

5 files changed

+58
-4
lines changed

5 files changed

+58
-4
lines changed
 

‎patching/src/main/java/org/jboss/as/patching/runner/AbstractFileTask.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.jboss.as.patching.PatchMessages;
3535
import org.jboss.as.patching.metadata.ContentModification;
3636
import org.jboss.as.patching.metadata.MiscContentItem;
37+
import org.jboss.as.patching.metadata.ModificationType;
3738

3839
/**
3940
* Base {@linkplain PatchingTask} for misc file updates.
@@ -79,7 +80,7 @@ byte[] backup(PatchingTaskContext context) throws IOException {
7980
byte[] apply(PatchingTaskContext context, PatchContentLoader loader) throws IOException {
8081
final MiscContentItem item = contentItem;
8182
if(item.isDirectory()) {
82-
if(! target.mkdir() && ! target.isDirectory()) {
83+
if(! target.mkdirs() && ! target.isDirectory()) {
8384
throw PatchMessages.MESSAGES.cannotCreateDirectory(target.getAbsolutePath());
8485
}
8586
return NO_CONTENT;

‎patching/src/main/java/org/jboss/as/patching/runner/AbstractPatchingTask.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public boolean prepare(final PatchingTaskContext context) throws IOException {
123123
final byte[] contentHash = contentItem.getContentHash();
124124
if(Arrays.equals(backupHash, contentHash)) {
125125
// Skip execute for misc items only
126-
skipExecution = contentItem.getContentType() == ContentType.MISC;
126+
skipExecution = contentItem.getContentType() == ContentType.MISC && backupHash != NO_CONTENT;
127127
return true;
128128
}
129129
// See if the content matches our expected target

‎patching/src/main/java/org/jboss/as/patching/runner/FileRemoveTask.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,16 @@ public boolean prepare(PatchingTaskContext context) throws IOException {
7474
backup(target, backup, Arrays.asList(item.getPath()), rollback, context);
7575
// See if the hash matches the metadata
7676

77+
boolean isEmptyDirectory = false;
78+
if (target.isDirectory()) {
79+
final File[] children = target.listFiles();
80+
if (children == null || children.length == 0) {
81+
isEmptyDirectory = true;
82+
}
83+
}
84+
7785
final byte[] expected = description.getModification().getTargetHash();
78-
final byte[] actual = HashUtils.hashFile(target);
86+
final byte[] actual = isEmptyDirectory ? NO_CONTENT : HashUtils.hashFile(target);
7987
return Arrays.equals(expected, actual);
8088
}
8189

‎patching/src/test/java/org/jboss/as/patching/runner/AbstractTaskTestCase.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.ArrayList;
3535
import java.util.List;
3636

37+
import javafx.scene.layout.Pane;
3738
import org.jboss.as.patching.DirectoryStructure;
3839
import org.jboss.as.patching.IoUtils;
3940
import org.jboss.as.patching.PatchingException;
@@ -101,8 +102,12 @@ protected PatchingResult rollback(String patchId) throws IOException, PatchingEx
101102
}
102103

103104
protected PatchingResult rollback(String patchId, final boolean rollbackTo) throws IOException, PatchingException {
105+
return rollback(patchId, rollbackTo, ContentVerificationPolicy.STRICT);
106+
}
107+
108+
protected PatchingResult rollback(String patchId, boolean rollbackTo, ContentVerificationPolicy policy) throws IOException, PatchingException {
104109
final PatchTool tool = newPatchTool();
105-
final PatchingResult result = tool.rollback(patchId, ContentVerificationPolicy.STRICT, rollbackTo, true);
110+
final PatchingResult result = tool.rollback(patchId, policy, rollbackTo, true);
106111
result.commit();
107112
return result;
108113
}

‎patching/src/test/java/org/jboss/as/patching/runner/FileTaskTestCase.java

+40
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package org.jboss.as.patching.runner;
2424

2525
import static org.jboss.as.patching.HashUtils.hashFile;
26+
import static org.jboss.as.patching.IoUtils.NO_CONTENT;
2627
import static org.jboss.as.patching.IoUtils.mkdir;
2728
import static org.jboss.as.patching.runner.PatchingAssert.assertFileContent;
2829
import static org.jboss.as.patching.runner.PatchingAssert.assertFileDoesNotExist;
@@ -41,9 +42,13 @@
4142
import java.io.File;
4243

4344
import org.jboss.as.patching.installation.Identity;
45+
import org.jboss.as.patching.metadata.ContentItem;
4446
import org.jboss.as.patching.metadata.ContentModification;
47+
import org.jboss.as.patching.metadata.MiscContentItem;
48+
import org.jboss.as.patching.metadata.ModificationType;
4549
import org.jboss.as.patching.metadata.Patch;
4650
import org.jboss.as.patching.metadata.PatchBuilder;
51+
import org.jboss.as.patching.tool.ContentVerificationPolicy;
4752
import org.jboss.as.patching.tool.PatchingResult;
4853
import org.junit.Test;
4954

@@ -225,5 +230,40 @@ public void testRemoveDirectoryAndRollback() throws Exception {
225230
assertTrue(subTwo.isFile());
226231
}
227232

233+
@Test
234+
public void testAddDirectory() throws Exception {
235+
236+
final ContentItem item = new MiscContentItem("dir", new String[] { "test"}, NO_CONTENT, true, false);
237+
final ContentModification addDir = new ContentModification(item, NO_CONTENT, ModificationType.ADD);
238+
239+
final String patchID = randomString();
240+
final Patch patch = PatchBuilder.create()
241+
.setPatchId(patchID)
242+
.setDescription(randomString())
243+
.oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion())
244+
.getParent()
245+
.addContentModification(addDir)
246+
.build();
247+
248+
// create the patch
249+
final File patchDir = mkdir(tempDir, patch.getPatchId());
250+
createPatchXMLFile(patchDir, patch);
251+
final File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
252+
253+
// Apply
254+
PatchingResult result = executePatch(zippedPatch);
255+
assertPatchHasBeenApplied(result, patch);
256+
257+
final File test = new File(env.getInstalledImage().getJbossHome(), "test");
258+
assertTrue(test.exists());
259+
assertTrue(test.isDirectory());
260+
final File dir = new File(test, "dir");
261+
assertTrue(dir.exists());
262+
assertTrue(dir.isDirectory());
263+
264+
rollback(patchID);
265+
266+
}
267+
228268
}
229269

0 commit comments

Comments
 (0)
Please sign in to comment.