Modified getEntryPaths() to only display the contents of the specified
path rather than every matching entry as per the spec.
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@375551 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/JarContent.java b/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/JarContent.java
index cca51cf..60184a9 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/JarContent.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/JarContent.java
@@ -297,12 +297,28 @@
private Object findNext()
{
+ // This method filters the entries of the zip file, such that
+ // it only displays the contents of the directory specified by
+ // the path argument; much like using "ls" to list the contents
+ // of a directory.
while (m_enumeration.hasMoreElements())
{
+ // Get the next zip entry.
ZipEntry entry = (ZipEntry) m_enumeration.nextElement();
- if (entry.getName().startsWith(m_path))
+ // Check to see if it is a child of the specified path.
+ if (!entry.getName().equals(m_path) && entry.getName().startsWith(m_path))
{
- return entry.getName();
+ // Verify that it is a child of the path and not a
+ // grandchild by examining its remaining path length.
+ // this code uses the knowledge that zip entries
+ // corresponding to directories end in '/'. It checks
+ // to see if the next occurrence of '/' is also the
+ // end of the string or if there are no more occurrences.
+ int idx = entry.getName().indexOf('/', m_path.length());
+ if ((idx < 0) || (idx == (entry.getName().length() - 1)))
+ {
+ return entry.getName();
+ }
}
}
return null;