You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by pa...@apache.org on 2002/03/09 02:44:55 UTC
cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources WARDirContext.java
patrickl 02/03/08 17:44:55
Modified: catalina/src/share/org/apache/naming/resources Tag:
tomcat_40_branch WARDirContext.java
Log:
Fix to handle war files that do not have separate ZipEntry objects for directories. Surprisingly, this is a valid format for a jar file. This fix emulates the functionality the JDK's jar command provides when unpacking jar files with missing directory entries.
Revision Changes Path
No revision
No revision
1.3.2.2 +30 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/WARDirContext.java
Index: WARDirContext.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/WARDirContext.java,v
retrieving revision 1.3.2.1
retrieving revision 1.3.2.2
diff -u -r1.3.2.1 -r1.3.2.2
--- WARDirContext.java 27 Feb 2002 02:55:44 -0000 1.3.2.1
+++ WARDirContext.java 9 Mar 2002 01:44:55 -0000 1.3.2.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/WARDirContext.java,v 1.3.2.1 2002/02/27 02:55:44 remm Exp $
- * $Revision: 1.3.2.1 $
- * $Date: 2002/02/27 02:55:44 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/WARDirContext.java,v 1.3.2.2 2002/03/09 01:44:55 patrickl Exp $
+ * $Revision: 1.3.2.2 $
+ * $Date: 2002/03/09 01:44:55 $
*
* ====================================================================
*
@@ -100,7 +100,7 @@
* WAR Directory Context implementation.
*
* @author Remy Maucherat
- * @version $Revision: 1.3.2.1 $ $Date: 2002/02/27 02:55:44 $
+ * @version $Revision: 1.3.2.2 $ $Date: 2002/03/09 01:44:55 $
*/
public class WARDirContext extends BaseDirContext {
@@ -788,6 +788,32 @@
ZipEntry entry = (ZipEntry) entryList.nextElement();
String name = normalize(entry);
int pos = name.lastIndexOf('/');
+ // Check that parent entries exist and, if not, create them.
+ // This fixes a bug for war files that don't record separate
+ // zip entries for the directories.
+ int currentPos = -1;
+ int lastPos = 0;
+ while ((currentPos = name.indexOf('/', lastPos)) != -1) {
+ Name parentName = new CompositeName(name.substring(0, lastPos));
+ Name childName = new CompositeName(name.substring(0, currentPos));
+ String entryName = name.substring(lastPos, currentPos);
+ // Parent should have been created in last cycle through
+ // this loop
+ Entry parent = treeLookup(parentName);
+ Entry child = treeLookup(childName);
+ if (child == null) {
+ // Create a new entry for missing entry and strip off
+ // the leading '/' character and appended on by the
+ // normalize method and add '/' character to end to
+ // signify that it is a directory entry
+ String zipName = name.substring(1, currentPos) + "/";
+ child = new Entry(entryName, new ZipEntry(zipName));
+ if (parent != null)
+ parent.addChild(child);
+ }
+ // Increment lastPos
+ lastPos = currentPos + 1;
+ }
String entryName = name.substring(pos + 1, name.length());
Name compositeName = new CompositeName(name.substring(0, pos));
Entry parent = treeLookup(compositeName);
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>