소스 검색

2008-06-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	When there is not enough space in disk when writing a chunk of 
data,
	aria2 now prints the message to the console to warn user and 
aborts
	its download. Not all downloads are canceled because some 
downloads
	may use another disk or partition. BUG#1640332
	* src/AbstractDiskWriter.cc
	* src/PeerAbstractCommand.cc
	* src/PeerAbstractCommand.h: Added onFailure() function for 
override.
	* src/PeerInteractionCommand.cc: In onFailure(), call 
RequestGroup::
	setHaltRequested(true) to cancel download.
	* src/PeerInteractionCommand.h
Tatsuhiro Tsujikawa 17 년 전
부모
커밋
1c2dd30bf7
6개의 변경된 파일36개의 추가작업 그리고 0개의 파일을 삭제
  1. 13 0
      ChangeLog
  2. 7 0
      src/AbstractDiskWriter.cc
  3. 6 0
      src/PeerAbstractCommand.cc
  4. 3 0
      src/PeerAbstractCommand.h
  5. 6 0
      src/PeerInteractionCommand.cc
  6. 1 0
      src/PeerInteractionCommand.h

+ 13 - 0
ChangeLog

@@ -1,3 +1,16 @@
+2008-06-16  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	When there is not enough space in disk when writing a chunk of data,
+	aria2 now prints the message to the console to warn user and aborts
+	its download. Not all downloads are canceled because some downloads
+	may use another disk or partition. BUG#1640332
+	* src/AbstractDiskWriter.cc
+	* src/PeerAbstractCommand.cc
+	* src/PeerAbstractCommand.h: Added onFailure() function for override.
+	* src/PeerInteractionCommand.cc: In onFailure(), call RequestGroup::
+	setHaltRequested(true) to cancel download.
+	* src/PeerInteractionCommand.h
+	
 2008-06-16  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Applied Ross's aria2-0.13.2+1-mingw-5.patch, which changes the type of

+ 7 - 0
src/AbstractDiskWriter.cc

@@ -41,6 +41,7 @@
 #include "DlAbortEx.h"
 #include "a2io.h"
 #include "StringFormat.h"
+#include "DownloadFailureException.h"
 #include <cerrno>
 #include <cstring>
 #include <cassert>
@@ -133,6 +134,12 @@ void AbstractDiskWriter::writeData(const unsigned char* data, size_t len, off_t
 {
   seek(offset);
   if(writeDataInternal(data, len) < 0) {
+    // If errno is ENOSPC(not enough space in device), throw
+    // DownloadFailureException and abort download instantly.
+    if(errno == ENOSPC) {
+      throw DownloadFailureException
+	(StringFormat(EX_FILE_WRITE, filename.c_str(), strerror(errno)).str());
+    }
     throw DlAbortEx(StringFormat(EX_FILE_WRITE, filename.c_str(), strerror(errno)).str());
   }
 }

+ 6 - 0
src/PeerAbstractCommand.cc

@@ -41,6 +41,7 @@
 #include "Logger.h"
 #include "message.h"
 #include "prefs.h"
+#include "DownloadFailureException.h"
 
 namespace aria2 {
 
@@ -83,6 +84,11 @@ bool PeerAbstractCommand::execute() {
       throw DlAbortEx(EX_TIME_OUT);
     }
     return executeInternal();
+  } catch(DownloadFailureException& err) {
+    logger->error(EX_DOWNLOAD_ABORTED, err);
+    onAbort();
+    onFailure();
+    return true;
   } catch(RecoverableException& err) {
     logger->debug(MSG_TORRENT_DOWNLOAD_ABORTED, err, cuid);
     logger->debug(MSG_PEER_BANNED,

+ 3 - 0
src/PeerAbstractCommand.h

@@ -58,6 +58,9 @@ protected:
   void setTimeout(time_t timeout) { this->timeout = timeout; }
   virtual bool prepareForNextPeer(time_t wait);
   virtual void onAbort() {};
+  // This function is called when DownloadFailureException is caught right after
+  // the invocation of onAbort().
+  virtual void onFailure() {};
   virtual bool exitBeforeExecute() = 0;
   virtual bool executeInternal() = 0;
   void setReadCheckSocket(const SharedHandle<SocketCore>& socket);

+ 6 - 0
src/PeerInteractionCommand.cc

@@ -63,6 +63,7 @@
 #include "DHTSetup.h"
 #include "DHTRegistry.h"
 #include "PieceStorage.h"
+#include "RequestGroup.h"
 #include <algorithm>
 
 namespace aria2 {
@@ -276,6 +277,11 @@ void PeerInteractionCommand::onAbort() {
   peerStorage->returnPeer(peer);
 }
 
+void PeerInteractionCommand::onFailure()
+{
+  _requestGroup->setHaltRequested(true);
+}
+
 bool PeerInteractionCommand::exitBeforeExecute()
 {
   return btRuntime->isHalt();

+ 1 - 0
src/PeerInteractionCommand.h

@@ -62,6 +62,7 @@ protected:
   virtual bool executeInternal();
   virtual bool prepareForNextPeer(time_t wait);
   virtual void onAbort();
+  virtual void onFailure();
   virtual bool exitBeforeExecute();
 public:
   PeerInteractionCommand(int32_t cuid,