]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1356] handle chunked / unknown length requests correctly
authorBrett Porter <brett@apache.org>
Fri, 5 Mar 2010 06:42:52 +0000 (06:42 +0000)
committerBrett Porter <brett@apache.org>
Fri, 5 Mar 2010 06:42:52 +0000 (06:42 +0000)
Merged from: r919307

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-1.3.x@919313 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResource.java

index 0b04010094d9b895444ca3b41a98b66a0b201f16..d08a3700df268a24a9eaf424a771be0341966581 100644 (file)
@@ -310,13 +310,16 @@ public class ArchivaDavResource
             }
 
             // TODO: a bad deployment shouldn't delete an existing file - do we need to write to a temporary location first?
-            if ( inputContext.getContentLength() != localFile.length() )
+            long expectedContentLength = inputContext.getContentLength();
+            long actualContentLength = localFile.length();
+            // length of -1 is given for a chunked request or unknown length, in which case we accept what was uploaded
+            if ( expectedContentLength >= 0 && expectedContentLength != actualContentLength )
             {
-                FileUtils.deleteQuietly( localFile );
-
                 String msg =
-                    "Content Header length was " + inputContext.getContentLength() + " but was " + localFile.length();
+                    "Content Header length was " + expectedContentLength + " but was " + actualContentLength;
                 log.debug( "Upload failed: " + msg );
+
+                FileUtils.deleteQuietly( localFile );
                 throw new DavException( HttpServletResponse.SC_BAD_REQUEST, msg );
             }