From 24bdbf9aa6790f95b14449fed62d83fd196a0124 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 4 Dec 2007 14:52:46 +0000 Subject: [PATCH] 2007-12-04 Tatsuhiro Tsujikawa Added --allow-piece-length-change option. * src/DefaultBtProgressInfoFile.cc * test/DefaultBtProgressInfoFileTest.cc * src/OptionHandlerFactory.cc * src/option_processing.cc * src/prefs.h * src/version_usage.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: duplicated result entry appears when exception is thrown in RequestGroup::createInitiateConnectionCommand(). * src/RequestGroupMan.cc (fillRequestGroupFromReserver): Add RequestGroup to _requestGroup after RequetGroup:: createInitiateConnectionCommand() succeeds. Externalized message * src/XML2SAXMetalinkProcessor.cc * src/message.h --- ChangeLog | 22 ++++++++++++++++++++++ doc/aria2c.1 | 10 ++++++++-- doc/aria2c.1.txt | 6 ++++++ src/DefaultBtProgressInfoFile.cc | 7 +++++++ src/OptionHandlerFactory.cc | 1 + src/RequestGroupMan.cc | 2 +- src/XML2SAXMetalinkProcessor.cc | 7 ++++--- src/message.h | 1 + src/option_processing.cc | 5 +++++ src/prefs.h | 2 ++ src/version_usage.cc | 11 ++++++++--- test/DefaultBtProgressInfoFileTest.cc | 1 + 12 files changed, 66 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5d6b161a..88829448 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2007-12-04 Tatsuhiro Tsujikawa + + Added --allow-piece-length-change option. + * src/DefaultBtProgressInfoFile.cc + * test/DefaultBtProgressInfoFileTest.cc + * src/OptionHandlerFactory.cc + * src/option_processing.cc + * src/prefs.h + * src/version_usage.cc + * doc/aria2c.1.txt + * doc/aria2c.1 + + Fixed: duplicated result entry appears when exception is thrown in + RequestGroup::createInitiateConnectionCommand(). + * src/RequestGroupMan.cc (fillRequestGroupFromReserver): + Add RequestGroup to _requestGroup after RequetGroup:: + createInitiateConnectionCommand() succeeds. + + Externalized message + * src/XML2SAXMetalinkProcessor.cc + * src/message.h + 2007-12-04 Tatsuhiro Tsujikawa Forced download abort when received negative response from http/ftp diff --git a/doc/aria2c.1 b/doc/aria2c.1 index ef556b9f..4360f45b 100644 --- a/doc/aria2c.1 +++ b/doc/aria2c.1 @@ -1,11 +1,11 @@ .\" Title: aria2c .\" Author: .\" Generator: DocBook XSL Stylesheets v1.73.1 -.\" Date: 11/29/2007 +.\" Date: 12/04/2007 .\" Manual: .\" Source: .\" -.TH "ARIA2C" "1" "11/29/2007" "" "" +.TH "ARIA2C" "1" "12/04/2007" "" "" .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) @@ -231,6 +231,12 @@ then, file name will be renamed\. See \-\-auto\-file\-renaming for details\. Def \fIfalse\fR .RE .PP +\-\-allow\-piece\-length\-change=\fItrue\fR|\fIfalse\fR +.RS 4 +If false is given, aria2 aborts download when a piece length is different from one in a control file\. If true is given, you can proceed but some download progress will be lost\. Default: +\fIfalse\fR +.RE +.PP \-Z, \-\-force\-sequential[=\fItrue\fR|\fIfalse\fR] .RS 4 Fetch URIs in the command\-line sequentially and download each URI in a separate session, like the usual command\-line download utilities\. Default: diff --git a/doc/aria2c.1.txt b/doc/aria2c.1.txt index 4b9f0f1e..f239bdcc 100644 --- a/doc/aria2c.1.txt +++ b/doc/aria2c.1.txt @@ -147,6 +147,12 @@ OPTIONS file name will be renamed. See --auto-file-renaming for details. Default: 'false' +--allow-piece-length-change='true'|'false':: + If false is given, aria2 aborts download when a piece length is different + from one in a control file. + If true is given, you can proceed but some download progress will be lost. + Default: 'false' + -Z, --force-sequential[='true'|'false']:: Fetch URIs in the command-line sequentially and download each URI in a separate session, like the usual command-line download utilities. diff --git a/src/DefaultBtProgressInfoFile.cc b/src/DefaultBtProgressInfoFile.cc index a1dde4cc..5d6a5a95 100644 --- a/src/DefaultBtProgressInfoFile.cc +++ b/src/DefaultBtProgressInfoFile.cc @@ -44,6 +44,7 @@ #include "File.h" #include "Util.h" #include "a2io.h" +#include "DownloadFailureException.h" #include #include @@ -256,8 +257,14 @@ void DefaultBtProgressInfoFile::load() } _pieceStorage->addInFlightPiece(inFlightPieces); } else { + int32_t numInFlightPiece; + in.read(reinterpret_cast(&numInFlightPiece), sizeof(numInFlightPiece)); BitfieldMan src(pieceLength, totalLength); src.setBitfield(savedBitfield, bitfieldLength); + if((src.getCompletedLength() || numInFlightPiece) && + !_option->getAsBool(PREF_ALLOW_PIECE_LENGTH_CHANGE)) { + throw new DownloadFailureException("WARNING: Detected a change in piece length. You can proceed with --allow-piece-length-change=true, but you may lose some download progress."); + } BitfieldMan dest(_dctx->getPieceLength(), totalLength); Util::convertBitfield(&dest, &src); _pieceStorage->setBitfield(dest.getBitfield(), dest.getBitfieldLength()); diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index 51e96612..5e134d1c 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -101,6 +101,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() handlers.push_back(new BooleanOptionHandler(PREF_ENABLE_HTTP_PIPELINING)); handlers.push_back(new UnitNumberOptionHandler(PREF_NO_FILE_ALLOCATION_LIMIT, 0)); handlers.push_back(new BooleanOptionHandler(PREF_ENABLE_DIRECT_IO)); + handlers.push_back(new BooleanOptionHandler(PREF_ALLOW_PIECE_LENGTH_CHANGE)); return handlers; } diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index 1515cafe..5fab60eb 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -151,8 +151,8 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e) temp.push_front(groupToAdd); continue; } - _requestGroups.push_back(groupToAdd); Commands commands = groupToAdd->createInitialCommand(e); + _requestGroups.push_back(groupToAdd); ++count; e->addCommand(commands); } catch(RecoverableException* ex) { diff --git a/src/XML2SAXMetalinkProcessor.cc b/src/XML2SAXMetalinkProcessor.cc index d905526e..5cb1052c 100644 --- a/src/XML2SAXMetalinkProcessor.cc +++ b/src/XML2SAXMetalinkProcessor.cc @@ -36,6 +36,7 @@ #include "BinaryStream.h" #include "MetalinkParserStateMachine.h" #include "Util.h" +#include "message.h" class SessionData { public: @@ -127,7 +128,7 @@ MetalinkerHandle XML2SAXMetalinkProcessor::parseFile(const string& filename) int32_t retval = xmlSAXUserParseFile(&mySAXHandler, sessionData.get(), filename.c_str()); if(retval != 0) { - throw new DlAbortEx("Cannot parse metalink XML file. XML may be malformed."); + throw new DlAbortEx(MSG_CANNOT_PARSE_METALINK); } return _stm->getResult(); } @@ -153,7 +154,7 @@ MetalinkerHandle XML2SAXMetalinkProcessor::parseFromBinaryStream(const BinaryStr break; } if(xmlParseChunk(ctx, (const char*)buf, res, 0) != 0) { - throw new DlAbortEx("Cannot parse metalink XML file. XML may be malformed."); + throw new DlAbortEx(MSG_CANNOT_PARSE_METALINK); } readOffset += res; } @@ -161,7 +162,7 @@ MetalinkerHandle XML2SAXMetalinkProcessor::parseFromBinaryStream(const BinaryStr xmlFreeParserCtxt(ctx); if(!_stm->finished()) { - throw new DlAbortEx("Cannot parse metalink XML file. XML may be malformed."); + throw new DlAbortEx(MSG_CANNOT_PARSE_METALINK); } return _stm->getResult(); } diff --git a/src/message.h b/src/message.h index 08312a0a..6d008515 100644 --- a/src/message.h +++ b/src/message.h @@ -130,6 +130,7 @@ #define MSG_STRING_INTEGER_CONVERSION_FAILURE _("Failed to convert string into value: %s") #define MSG_RESOURCE_NOT_FOUND _("Resource not found") #define MSG_FILE_RENAMED _("File already exists. Renamed to %s.") +#define MSG_CANNOT_PARSE_METALINK _("Cannot parse metalink XML file. XML may be malformed.") #define EX_TIME_OUT _("Timeout.") #define EX_INVALID_CHUNK_SIZE _("Invalid chunk size.") diff --git a/src/option_processing.cc b/src/option_processing.cc index 0b2917e7..6af3bf6d 100644 --- a/src/option_processing.cc +++ b/src/option_processing.cc @@ -127,6 +127,7 @@ Option* option_processing(int argc, char* const argv[]) op->put(PREF_MAX_HTTP_PIPELINING, "2"); op->put(PREF_SEED_RATIO, "1.0"); op->put(PREF_ENABLE_DIRECT_IO, V_FALSE); + op->put(PREF_ALLOW_PIECE_LENGTH_CHANGE, V_FALSE); while(1) { int optIndex = 0; int lopt; @@ -178,6 +179,7 @@ Option* option_processing(int argc, char* const argv[]) #ifdef ENABLE_DIRECT_IO { PREF_ENABLE_DIRECT_IO, optional_argument, &lopt, 210 }, #endif // ENABLE_DIRECT_IO + { PREF_ALLOW_PIECE_LENGTH_CHANGE, required_argument, &lopt, 211 }, #if defined ENABLE_BITTORRENT || ENABLE_METALINK { "show-files", no_argument, NULL, 'S' }, { "select-file", required_argument, &lopt, 21 }, @@ -331,6 +333,9 @@ Option* option_processing(int argc, char* const argv[]) case 210: cmdstream << PREF_ENABLE_DIRECT_IO << "=" << toBoolArg(optarg) << "\n"; break; + case 211: + cmdstream << PREF_ALLOW_PIECE_LENGTH_CHANGE << "=" << optarg << "\n"; + break; } break; } diff --git a/src/prefs.h b/src/prefs.h index 3933b21f..2e70a0ae 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -117,6 +117,8 @@ #define PREF_PARAMETERIZED_URI "parameterized-uri" // value: true | false #define PREF_ENABLE_DIRECT_IO "enable-direct-io" +// value: true | false +#define PREF_ALLOW_PIECE_LENGTH_CHANGE "allow-piece-length-change" /** * FTP related preferences diff --git a/src/version_usage.cc b/src/version_usage.cc index 354858ee..4fa81fa4 100644 --- a/src/version_usage.cc +++ b/src/version_usage.cc @@ -171,9 +171,14 @@ void showUsage() { << DEFAULT_MSG << "false" << "\n"; #endif // ENABLE_DIRECT_IO cout << _(" --allow-overwrite=true|false If false, aria2 doesn't download a file which\n" - " already exists but the corresponding .aria2 file\n" - " doesn't exist.\n" - " Default: false") << endl; + " already exists but the corresponding .aria2 file\n" + " doesn't exist.\n" + " Default: false") << endl; + cout << _(" --allow-piece-length-change=true|false If false is given, aria2 aborts download\n" + " when a piece length is different from one in\n" + " a control file. If true is given, you can proceed\n" + " but some download progress will be lost.") << "\n" + << DEFAULT_MSG << "false" << "\n"; cout << _(" -Z, --force-sequential[=true|false] Fetch URIs in the command-line sequentially\n" " and download each URI in a separate session, like\n" " the usual command-line download utilities.\n" diff --git a/test/DefaultBtProgressInfoFileTest.cc b/test/DefaultBtProgressInfoFileTest.cc index c704e696..d87c739e 100644 --- a/test/DefaultBtProgressInfoFileTest.cc +++ b/test/DefaultBtProgressInfoFileTest.cc @@ -169,6 +169,7 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt() void DefaultBtProgressInfoFileTest::testLoad_nonBt_pieceLengthShorter() { initializeMembers(512, 81920); + _option->put(PREF_ALLOW_PIECE_LENGTH_CHANGE, V_TRUE); SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(512, 81920, "load-nonBt");