From: <jbo...@li...> - 2006-03-05 16:15:32
|
Author: mnasato Date: 2006-03-05 11:15:21 -0500 (Sun, 05 Mar 2006) New Revision: 2753 Modified: trunk/labs/davcache/src/net/sf/davcache/WebdavServlet.java Log: fail in COPY if missing destination parent path [#16] Modified: trunk/labs/davcache/src/net/sf/davcache/WebdavServlet.java =================================================================== --- trunk/labs/davcache/src/net/sf/davcache/WebdavServlet.java 2006-03-05 15:52:32 UTC (rev 2752) +++ trunk/labs/davcache/src/net/sf/davcache/WebdavServlet.java 2006-03-05 16:15:21 UTC (rev 2753) @@ -134,6 +134,13 @@ response.sendError(HttpServletResponse.SC_FORBIDDEN, "Source and destination are the same"); return; } + String parentPath = getParentPath(destinationPath); + if (parentPath != null && !store.exists(parentPath)) + { + logger.debug("cannot copy to destination; parent does not exist: '" + destinationPath + "'"); + response.sendError(HttpServletResponse.SC_CONFLICT, "Conflict: destination parent path does not exist"); + return; + } boolean overwrite = "T".equalsIgnoreCase(request.getHeader("Overwrite")); boolean destinationAlreadyExists = store.exists(destinationPath); if (!overwrite && destinationAlreadyExists) @@ -355,14 +362,6 @@ } } - private String getParentPath(String path) - { - int slash = path.lastIndexOf('/'); - if (slash == -1) - return null; - return path.substring(0, slash); - } - protected void doPropFind(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { int depth = getDepth(request); @@ -463,7 +462,7 @@ path = path.substring(path.indexOf("/", schema + 3)); } String contextPath = request.getContextPath(); - return path.substring(contextPath.length()); + return stripSlash(path.substring(contextPath.length())); } private String getAbsolutePath(HttpServletRequest request) @@ -471,6 +470,14 @@ return stripSlash(request.getRequestURI()); } + private String getParentPath(String path) + { + int slash = path.lastIndexOf('/'); + if (slash == -1) + return null; + return path.substring(0, slash); + } + private String stripSlash(String path) { if (path.endsWith("/")) |