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
pull/1/head
Tatsuhiro Tsujikawa 2010-09-13 11:47:04 +00:00
parent 5bf8a53b3f
commit 97953dd1ae
3 changed files with 28 additions and 15 deletions

View File

@ -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.

View File

@ -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;
}

View File

@ -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;
}