Bladeren bron

Added additional error_code::Values(9 through 14).

Tatsuhiro Tsujikawa 15 jaren geleden
bovenliggende
commit
ecbc05012c
6 gewijzigde bestanden met toevoegingen van 42 en 24 verwijderingen
  1. 3 2
      src/AbstractDiskWriter.cc
  2. 3 2
      src/DefaultBtProgressInfoFile.cc
  3. 3 2
      src/FtpNegotiationCommand.cc
  4. 3 2
      src/HttpResponseCommand.cc
  5. 24 16
      src/RequestGroup.cc
  6. 6 0
      src/error_code.h

+ 3 - 2
src/AbstractDiskWriter.cc

@@ -162,10 +162,11 @@ void AbstractDiskWriter::writeData(const unsigned char* data, size_t len, off_t
     // If errno is ENOSPC(not enough space in device), throw
     // DownloadFailureException and abort download instantly.
     if(errNum == ENOSPC) {
-      throw DOWNLOAD_FAILURE_EXCEPTION
+      throw DOWNLOAD_FAILURE_EXCEPTION2
         (fmt(EX_FILE_WRITE,
              filename_.c_str(),
-             util::safeStrerror(errNum).c_str()));
+             util::safeStrerror(errNum).c_str()),
+         error_code::NOT_ENOUGH_DISK_SPACE);
     } else {
       throw DL_ABORT_EX
         (fmt(EX_FILE_WRITE,

+ 3 - 2
src/DefaultBtProgressInfoFile.cc

@@ -409,10 +409,11 @@ void DefaultBtProgressInfoFile::load()
     src.setBitfield(savedBitfield, bitfieldLength);
     if((src.getCompletedLength() || numInFlightPiece) &&
        !option_->getAsBool(PREF_ALLOW_PIECE_LENGTH_CHANGE)) {
-      throw DOWNLOAD_FAILURE_EXCEPTION
+      throw DOWNLOAD_FAILURE_EXCEPTION2
         ("WARNING: Detected a change in piece length. You can proceed with"
          " --allow-piece-length-change=true, but you may lose some download"
-         " progress.");
+         " progress.",
+         error_code::PIECE_LENGTH_CHANGED);
     }
     BitfieldMan dest(dctx_->getPieceLength(), totalLength);
     util::convertBitfield(&dest, &src);

+ 3 - 2
src/FtpNegotiationCommand.cc

@@ -367,9 +367,10 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
   getRequestGroup()->preDownloadProcessing();
   if(getDownloadEngine()->getRequestGroupMan()->
      isSameFileBeingDownloaded(getRequestGroup())) {
-    throw DOWNLOAD_FAILURE_EXCEPTION
+    throw DOWNLOAD_FAILURE_EXCEPTION2
       (fmt(EX_DUPLICATE_FILE_DOWNLOAD,
-           getRequestGroup()->getFirstFilePath().c_str()));
+           getRequestGroup()->getFirstFilePath().c_str()),
+       error_code::DUPLICATE_DOWNLOAD);
   }
   if(totalLength == 0) {
 

+ 3 - 2
src/HttpResponseCommand.cc

@@ -213,9 +213,10 @@ bool HttpResponseCommand::executeInternal()
     getRequestGroup()->preDownloadProcessing();
     if(getDownloadEngine()->getRequestGroupMan()->
        isSameFileBeingDownloaded(getRequestGroup())) {
-      throw DOWNLOAD_FAILURE_EXCEPTION
+      throw DOWNLOAD_FAILURE_EXCEPTION2
         (fmt(EX_DUPLICATE_FILE_DOWNLOAD,
-             getRequestGroup()->getFirstFilePath().c_str()));
+             getRequestGroup()->getFirstFilePath().c_str()),
+         error_code::DUPLICATE_DOWNLOAD);
     }
     // update last modified time
     updateLastModifiedTime(httpResponse->getLastModifiedTime());

+ 24 - 16
src/RequestGroup.cc

@@ -298,18 +298,20 @@ void RequestGroup::createInitialCommand
       if(btRegistry->getDownloadContext(torrentAttrs->infoHash)) {
         // TODO If metadataGetMode == false and each FileEntry has
         // URI, then go without BT.
-        throw DOWNLOAD_FAILURE_EXCEPTION
+        throw DOWNLOAD_FAILURE_EXCEPTION2
           (fmt("InfoHash %s is already registered.",
-               bittorrent::getInfoHashString(downloadContext_).c_str()));
+               bittorrent::getInfoHashString(downloadContext_).c_str()),
+           error_code::DUPLICATE_INFO_HASH);
       }
       if(metadataGetMode) {
         // Use UnknownLengthPieceStorage.
         initPieceStorage();
       } else {
         if(e->getRequestGroupMan()->isSameFileBeingDownloaded(this)) {
-          throw DOWNLOAD_FAILURE_EXCEPTION
+          throw DOWNLOAD_FAILURE_EXCEPTION2
             (fmt(EX_DUPLICATE_FILE_DOWNLOAD,
-                 downloadContext_->getBasePath().c_str()));
+                 downloadContext_->getBasePath().c_str()),
+             error_code::DUPLICATE_DOWNLOAD);
         }
         initPieceStorage();
         if(downloadContext_->getFileEntries().size() > 1) {
@@ -413,9 +415,10 @@ void RequestGroup::createInitialCommand
              !option_->getAsBool(PREF_ALLOW_OVERWRITE) &&
              !option_->getAsBool(PREF_BT_SEED_UNVERIFIED)) {
             // TODO we need this->haltRequested = true?
-            throw DOWNLOAD_FAILURE_EXCEPTION
+            throw DOWNLOAD_FAILURE_EXCEPTION2
               (fmt(MSG_FILE_ALREADY_EXISTS,
-                   downloadContext_->getBasePath().c_str()));
+                   downloadContext_->getBasePath().c_str()),
+               error_code::FILE_ALREADY_EXISTS);
           } else {
             pieceStorage_->getDiskAdaptor()->openFile();
           }
@@ -477,9 +480,10 @@ void RequestGroup::createInitialCommand
       createNextCommand(commands, e, 1);
     } else {
       if(e->getRequestGroupMan()->isSameFileBeingDownloaded(this)) {
-        throw DOWNLOAD_FAILURE_EXCEPTION
+        throw DOWNLOAD_FAILURE_EXCEPTION2
           (fmt(EX_DUPLICATE_FILE_DOWNLOAD,
-               downloadContext_->getBasePath().c_str()));
+               downloadContext_->getBasePath().c_str()),
+           error_code::DUPLICATE_DOWNLOAD);
       }
       SharedHandle<BtProgressInfoFile> progressInfoFile
         (new DefaultBtProgressInfoFile
@@ -503,9 +507,10 @@ void RequestGroup::createInitialCommand
     // In this context, multiple FileEntry objects are in
     // DownloadContext.
     if(e->getRequestGroupMan()->isSameFileBeingDownloaded(this)) {
-      throw DOWNLOAD_FAILURE_EXCEPTION
+      throw DOWNLOAD_FAILURE_EXCEPTION2
         (fmt(EX_DUPLICATE_FILE_DOWNLOAD,
-             downloadContext_->getBasePath().c_str()));
+             downloadContext_->getBasePath().c_str()),
+         error_code::DUPLICATE_DOWNLOAD);
     }
     initPieceStorage();
     if(downloadContext_->getFileEntries().size() > 1) {
@@ -526,9 +531,10 @@ void RequestGroup::createInitialCommand
         if(!isCheckIntegrityReady() &&
            !option_->getAsBool(PREF_ALLOW_OVERWRITE)) {
           // TODO we need this->haltRequested = true?
-          throw DOWNLOAD_FAILURE_EXCEPTION
+          throw DOWNLOAD_FAILURE_EXCEPTION2
             (fmt(MSG_FILE_ALREADY_EXISTS,
-                 downloadContext_->getBasePath().c_str()));
+                 downloadContext_->getBasePath().c_str()),
+             error_code::FILE_ALREADY_EXISTS);
         } else {
           pieceStorage_->getDiskAdaptor()->openFile();
         }
@@ -763,14 +769,16 @@ void RequestGroup::shouldCancelDownloadForSafety()
       if(tryAutoFileRenaming()) {
         A2_LOG_NOTICE(fmt(MSG_FILE_RENAMED, getFirstFilePath().c_str()));
       } else {
-        throw DOWNLOAD_FAILURE_EXCEPTION
+        throw DOWNLOAD_FAILURE_EXCEPTION2
           (fmt("File renaming failed: %s",
-               getFirstFilePath().c_str()));
+               getFirstFilePath().c_str()),
+           error_code::FILE_RENAMING_FAILED);
       }
     } else {
-      throw DOWNLOAD_FAILURE_EXCEPTION
+      throw DOWNLOAD_FAILURE_EXCEPTION2
         (fmt(MSG_FILE_ALREADY_EXISTS,
-             getFirstFilePath().c_str()));
+             getFirstFilePath().c_str()),
+         error_code::FILE_ALREADY_EXISTS);
     }
   }
 }

+ 6 - 0
src/error_code.h

@@ -52,6 +52,12 @@ enum Value {
   NETWORK_PROBLEM = 6,
   IN_PROGRESS = 7,
   CANNOT_RESUME = 8,
+  NOT_ENOUGH_DISK_SPACE = 9,
+  PIECE_LENGTH_CHANGED = 10,
+  DUPLICATE_DOWNLOAD = 11,
+  DUPLICATE_INFO_HASH = 12,
+  FILE_ALREADY_EXISTS = 13,
+  FILE_RENAMING_FAILED = 14
 };
 
 } // namespace error_code