Browse Source

2010-09-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Fixed the bug that error occurs when downloading zero-length file.
	* src/FtpNegotiationCommand.cc
	* src/HttpResponseCommand.cc
Tatsuhiro Tsujikawa 15 years ago
parent
commit
97953dd1ae
3 changed files with 28 additions and 15 deletions
  1. 6 0
      ChangeLog
  2. 3 1
      src/FtpNegotiationCommand.cc
  3. 19 14
      src/HttpResponseCommand.cc

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2010-09-13  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Fixed the bug that error occurs when downloading zero-length file.
+	* src/FtpNegotiationCommand.cc
+	* src/HttpResponseCommand.cc
+
 2010-09-12  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Fixed compile error without OpenSSL/GnuTLS.

+ 3 - 1
src/FtpNegotiationCommand.cc

@@ -403,7 +403,8 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
       return false;
     }
 
-    if(getRequestGroup()->downloadFinishedByFileLength()) {
+    if(getDownloadContext()->knowsTotalLength() &&
+       getRequestGroup()->downloadFinishedByFileLength()) {
       getRequestGroup()->initPieceStorage();
       getPieceStorage()->markAllPiecesDone();
       // TODO It would be good to issue ChecksumCheckIntegrity here
@@ -425,6 +426,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
 
     if(getDownloadContext()->knowsTotalLength()) {
       sequence_ = SEQ_DOWNLOAD_ALREADY_COMPLETED;
+      getPieceStorage()->markAllPiecesDone();
       poolConnection();
       return false;
     }

+ 19 - 14
src/HttpResponseCommand.cc

@@ -375,8 +375,21 @@ bool HttpResponseCommand::handleOtherEncoding
     return prepareForRetry(0);
   }
 
+  // In this context, knowsTotalLength() is true only when the file is
+  // really zero-length.
+
+  SharedHandle<StreamFilter> streamFilter =
+    getTransferEncodingStreamFilter
+    (httpResponse,
+     getContentEncodingStreamFilter(httpResponse));
+  // If chunked transfer-encoding is specified, we have to read end of
+  // chunk markers(0\r\n\r\n, for example).
+  bool chunkedUsed = !streamFilter.isNull() &&
+    streamFilter->getName() == ChunkedDecodingStreamFilter::NAME;
+
   // For zero-length file, check existing file comparing its size
-  if(getRequestGroup()->downloadFinishedByFileLength()) {
+  if(!chunkedUsed && getDownloadContext()->knowsTotalLength() &&
+     getRequestGroup()->downloadFinishedByFileLength()) {
     getRequestGroup()->initPieceStorage();
     getPieceStorage()->markAllPiecesDone();
     // This is zero-size file, so hash check is no use.
@@ -392,19 +405,11 @@ bool HttpResponseCommand::handleOtherEncoding
   getRequestGroup()->initPieceStorage();
   getPieceStorage()->getDiskAdaptor()->initAndOpenFile();
 
-  SharedHandle<StreamFilter> streamFilter =
-    getTransferEncodingStreamFilter
-    (httpResponse,
-     getContentEncodingStreamFilter(httpResponse));
-  
-  // In this context, knowsTotalLength() is true only when the file is
-  // really zero-length.
-  if(getDownloadContext()->knowsTotalLength() &&
-     (streamFilter.isNull() ||
-      streamFilter->getName() != ChunkedDecodingStreamFilter::NAME)) {
-    // If chunked transfer-encoding is specified, we have to read end
-    // of chunk markers(0\r\n\r\n, for example), so cannot pool
-    // connection here.
+  // Local file size becomes zero when DiskAdaptor::initAndOpenFile()
+  // is called. So zero-length file is complete if chunked encoding is
+  // not used.
+  if(!chunkedUsed && getDownloadContext()->knowsTotalLength()) {
+    getRequestGroup()->getPieceStorage()->markAllPiecesDone();
     poolConnection();
     return true;
   }