From 16722b559dd2bbc6325ddebf251ef307851185d8 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 26 Dec 2007 15:11:42 +0000 Subject: [PATCH] 2007-12-27 Tatsuhiro Tsujikawa Remove a defunct control file. A defunct control file means that while it exists, but the corresponding download file is missing. After its removal, a download restarts from the beginning. * src/RequestGroup.cc * src/message.h --- ChangeLog | 8 ++++++++ src/RequestGroup.cc | 14 ++++++++++++++ src/message.h | 1 + 3 files changed, 23 insertions(+) diff --git a/ChangeLog b/ChangeLog index f14a21e8..bc6f84bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-12-27 Tatsuhiro Tsujikawa + + Remove a defunct control file. A defunct control file means that while + it exists, but the corresponding download file is missing. + After its removal, a download restarts from the beginning. + * src/RequestGroup.cc + * src/message.h + 2007-12-26 Tatsuhiro Tsujikawa Allocate bitfield in Peer when it is really used. More specifically, diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index 08264300..358d8693 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -192,6 +192,13 @@ Commands RequestGroup::createInitialCommand(DownloadEngine* e) BtRegistry::registerPeerObjectCluster(btContext->getInfoHashAsString(), new PeerObjectCluster()); + // Remove the control file if download file doesn't exist + if(progressInfoFile->exists() && !_pieceStorage->getDiskAdaptor()->fileExists()) { + progressInfoFile->removeFile(); + _logger->notice(MSG_REMOVED_DEFUNCT_CONTROL_FILE, + progressInfoFile->getFilename().c_str(), + _pieceStorage->getDiskAdaptor()->getFilePath().c_str()); + } // Call Load, Save and file allocation command here if(progressInfoFile->exists()) { // load .aria2 file if it exists. @@ -302,6 +309,13 @@ void RequestGroup::loadAndOpenFile(const BtProgressInfoFileHandle& progressInfoF _pieceStorage->getDiskAdaptor()->initAndOpenFile(); return; } + // Remove the control file if download file doesn't exist + if(progressInfoFile->exists() && !_pieceStorage->getDiskAdaptor()->fileExists()) { + progressInfoFile->removeFile(); + _logger->notice(MSG_REMOVED_DEFUNCT_CONTROL_FILE, + progressInfoFile->getFilename().c_str(), + _pieceStorage->getDiskAdaptor()->getFilePath().c_str()); + } if(progressInfoFile->exists()) { progressInfoFile->load(); _pieceStorage->getDiskAdaptor()->openExistingFile(); diff --git a/src/message.h b/src/message.h index 3847fdf3..65312713 100644 --- a/src/message.h +++ b/src/message.h @@ -133,6 +133,7 @@ #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 MSG_TOO_SMALL_PAYLOAD_SIZE _("Too small payload size for %s, size=%d.") +#define MSG_REMOVED_DEFUNCT_CONTROL_FILE _("Removed the defunct control file %s because the download file %s doesn't exist.") #define EX_TIME_OUT _("Timeout.") #define EX_INVALID_CHUNK_SIZE _("Invalid chunk size.")