Author: markt Date: Thu Aug 10 21:09:31 2017 New Revision: 1804729 URL: http://svn.apache.org/viewvc?rev=1804729&view=rev Log: Correct regression in r1804604 that broke WebDAV.
Modified: tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/FileDirContext.java tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/VirtualDirContext.java tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Modified: tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/FileDirContext.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/FileDirContext.java?rev=1804729&r1=1804728&r2=1804729&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/FileDirContext.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/FileDirContext.java Thu Aug 10 21:09:31 2017 @@ -198,7 +198,7 @@ public class FileDirContext extends Base @Override protected Object doLookup(String name) { Object result = null; - File file = file(name); + File file = file(name, true); if (file == null) return null; @@ -235,7 +235,7 @@ public class FileDirContext extends Base public void unbind(String name) throws NamingException { - File file = file(name); + File file = file(name, true); if (file == null) throw new NameNotFoundException( @@ -262,14 +262,14 @@ public class FileDirContext extends Base @Override public void rename(String oldName, String newName) throws NamingException { - File file = file(oldName); + File file = file(oldName, true); if (file == null) { throw new NameNotFoundException(sm.getString("resources.notFound", oldName)); } - File newFile = file(newName); - if (newName == null) { + File newFile = file(newName, false); + if (newFile == null) { throw new NamingException(sm.getString("resources.renameFail", oldName, newName)); } @@ -296,7 +296,7 @@ public class FileDirContext extends Base protected List<NamingEntry> doListBindings(String name) throws NamingException { - File file = file(name); + File file = file(name, true); if (file == null) return null; @@ -400,7 +400,7 @@ public class FileDirContext extends Base throws NamingException { // Building attribute list - File file = file(name); + File file = file(name, true); if (file == null) return null; @@ -473,7 +473,7 @@ public class FileDirContext extends Base // Note: No custom attributes allowed - File file = file(name); + File file = file(name, false); if (file == null) { throw new NamingException(sm.getString("resources.bindFailed", name)); } @@ -511,7 +511,7 @@ public class FileDirContext extends Base // Note: No custom attributes allowed // Check obj type - File file = file(name); + File file = file(name, false); if (file == null) { throw new NamingException(sm.getString("resources.bindFailed", name)); } @@ -594,7 +594,7 @@ public class FileDirContext extends Base public DirContext createSubcontext(String name, Attributes attrs) throws NamingException { - File file = file(name); + File file = file(name, false); if (file == null) { throw new NamingException(sm.getString("resources.bindFailed", name)); } @@ -770,6 +770,7 @@ public class FileDirContext extends Base } + /** * Return a File object representing the specified normalized * context-relative path if it exists and is readable. Otherwise, @@ -778,9 +779,27 @@ public class FileDirContext extends Base * @param name Normalized context-relative path (with leading '/') */ protected File file(String name) { + return file(name, true); + } + + /** + * Return a File object representing the specified normalized + * context-relative path if it exists and is readable. Otherwise, + * return <code>null</code>. + * + * @param name Normalized context-relative path (with leading '/') + * @param mustExist Must the specified resource exist? + */ + protected File file(String name, boolean mustExist) { File file = new File(base, name); - if (file.exists() && file.canRead()) { + return validate(file, mustExist, absoluteBase); + } + + + protected File validate(File file, boolean mustExist, String absoluteBase) { + + if (!mustExist || file.exists() && file.canRead()) { if (allowLinking) return file; Modified: tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/VirtualDirContext.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/VirtualDirContext.java?rev=1804729&r1=1804728&r2=1804729&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/VirtualDirContext.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/VirtualDirContext.java Thu Aug 10 21:09:31 2017 @@ -76,7 +76,8 @@ public class VirtualDirContext extends F * be listed twice. * </p> * - * @param path + * @param path The set of file system paths and virtual paths to map them to + * in the required format */ public void setExtraResourcePaths(String path) { extraResourcePaths = path; @@ -106,13 +107,13 @@ public class VirtualDirContext extends F } path = resSpec.substring(0, idx); } - String dir = resSpec.substring(idx + 1); + File dir = new File(resSpec.substring(idx + 1)); List<String> resourcePaths = mappedResourcePaths.get(path); if (resourcePaths == null) { resourcePaths = new ArrayList<String>(); mappedResourcePaths.put(path, resourcePaths); } - resourcePaths.add(dir); + resourcePaths.add(dir.getAbsolutePath()); } } if (mappedResourcePaths.isEmpty()) { @@ -151,7 +152,8 @@ public class VirtualDirContext extends F String resourcesDir = dirList.get(0); if (name.equals(path)) { File f = new File(resourcesDir); - if (f.exists() && f.canRead()) { + f = validate(f, true, resourcesDir); + if (f != null) { return new FileResourceAttributes(f); } } @@ -159,7 +161,8 @@ public class VirtualDirContext extends F if (name.startsWith(path)) { String res = name.substring(path.length()); File f = new File(resourcesDir + "/" + res); - if (f.exists() && f.canRead()) { + f = validate(f, true, resourcesDir); + if (f != null) { return new FileResourceAttributes(f); } } @@ -168,9 +171,16 @@ public class VirtualDirContext extends F throw initialException; } + @Override protected File file(String name) { - File file = super.file(name); + return file(name, true); + } + + + @Override + protected File file(String name, boolean mustExist) { + File file = super.file(name, true); if (file != null || mappedResourcePaths == null) { return file; } @@ -185,7 +195,8 @@ public class VirtualDirContext extends F if (name.equals(path)) { for (String resourcesDir : dirList) { file = new File(resourcesDir); - if (file.exists() && file.canRead()) { + file = validate(file, true, resourcesDir); + if (file != null) { return file; } } @@ -194,7 +205,8 @@ public class VirtualDirContext extends F String res = name.substring(path.length()); for (String resourcesDir : dirList) { file = new File(resourcesDir, res); - if (file.exists() && file.canRead()) { + file = validate(file, true, resourcesDir); + if (file != null) { return file; } } @@ -229,7 +241,8 @@ public class VirtualDirContext extends F if (res != null) { for (String resourcesDir : dirList) { File f = new File(resourcesDir, res); - if (f.exists() && f.canRead() && f.isDirectory()) { + f = validate(f, true, resourcesDir); + if (f != null && f.isDirectory()) { List<NamingEntry> virtEntries = super.list(f); for (NamingEntry entry : virtEntries) { // filter duplicate @@ -264,7 +277,8 @@ public class VirtualDirContext extends F if (name.equals(path)) { for (String resourcesDir : dirList) { File f = new File(resourcesDir); - if (f.exists() && f.canRead()) { + f = validate(f, true, resourcesDir); + if (f != null) { if (f.isFile()) { return new FileResource(f); } @@ -280,7 +294,8 @@ public class VirtualDirContext extends F String res = name.substring(path.length()); for (String resourcesDir : dirList) { File f = new File(resourcesDir + "/" + res); - if (f.exists() && f.canRead()) { + f = validate(f, true, resourcesDir); + if (f != null) { if (f.isFile()) { return new FileResource(f); } Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1804729&r1=1804728&r2=1804729&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu Aug 10 21:09:31 2017 @@ -58,6 +58,13 @@ issues do not "pop up" wrt. others). --> <section name="Tomcat 7.0.81 (violetagg)"> + <subsection name="Catalina"> + <changelog> + <fix> + Correct regression in 7.0.80 that broke WebDAV. (markt) + </fix> + </changelog> + </subsection> </section> <section name="Tomcat 7.0.80 (violetagg)"> <subsection name="Catalina"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org