]> 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:09:53 +0000 (06:09 +0000)
committerBrett Porter <brett@apache.org>
Fri, 5 Mar 2010 06:09:53 +0000 (06:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@919307 13f79535-47bb-0310-9956-ffa450edef68

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

index c2bfb75edf65fce96af19ed7e37fee5addc277d2..ee155adc1064b481578d7fd23c9b9bf9d2a2fea6 100644 (file)
@@ -303,13 +303,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 );
             }