Skip to content

Commit

Permalink
[SHRINKWRAP-455] Fixed path containing children delete from imported …
Browse files Browse the repository at this point in the history
…archive
  • Loading branch information
mmatloka authored and ALRubinger committed Apr 19, 2013
1 parent 6ef6244 commit 9883f24
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -306,7 +308,11 @@ private Node removeNodeRecursively(final NodeImpl node, final ArchivePath path)
}
// Recursively delete children if present
if (node.getChildren() != null) {
for (Node child : node.getChildren()) {
final Set<Node> children = node.getChildren();

// can't remove from collection inside of the iteration
final Set<Node> childrenCopy = new HashSet<Node>(children);
for (Node child : childrenCopy) {
node.removeChild(child);
content.remove(child.getPath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,26 @@ public void testDeleteAssetRequiresStringPath() throws Exception {
Assert.fail("Should have throw an IllegalArgumentException");
}

/**
* Delete directory which contains children.
*/
@Test
public void testDeletePathWithChildren() {
// given
final Archive<T> archive = getArchive();
final String dirName = "dir";
archive.addAsDirectories(dirName);
archive.add(new StringAsset("asset"), dirName, "abc.txt").add(new StringAsset("asset"), dirName, "cde.txt");
archive.add(new StringAsset("other"), "other.txt");

// when
archive.delete("dir");

// then
Assert.assertFalse(archive.contains(dirName));
Assert.assertEquals(1, archive.getContent().size());
}

/**
* Ensure an asset can be retrieved by its path
*
Expand Down

0 comments on commit 9883f24

Please sign in to comment.