tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From patri...@apache.org
Subject cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources WARDirContext.java
Date Thu, 28 Feb 2002 07:04:37 GMT
patrickl    02/02/27 23:04:37

  Modified:    catalina/src/share/org/apache/naming/resources
                        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
  1.5       +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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- WARDirContext.java	27 Feb 2002 01:17:00 -0000	1.4
  +++ WARDirContext.java	28 Feb 2002 07:04:36 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/WARDirContext.java,v
1.4 2002/02/27 01:17:00 craigmcc Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/02/27 01:17:00 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/WARDirContext.java,v
1.5 2002/02/28 07:04:36 patrickl Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/02/28 07:04:36 $
    *
    * ====================================================================
    *
  @@ -100,7 +100,7 @@
    * WAR Directory Context implementation.
    *
    * @author Remy Maucherat
  - * @version $Revision: 1.4 $ $Date: 2002/02/27 01:17:00 $
  + * @version $Revision: 1.5 $ $Date: 2002/02/28 07:04:36 $
    */
   
   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:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message