mirror of https://github.com/aria2/aria2
2007-05-23 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Change file mode to 666: * src/common.h (OPEN_MODE): New definition. * src/File.cc * src/Util.cc * src/Directry.cc * src/AbstractDiskWriter.cc Change the level of log message "download aborted" to debug: * src/PeerAbstractCommand.cc (execute) * src/RequestGroup.h (RequestGroup): Initialized _hintTotalLength to 0. * src/TrackerWatcherCommand.cc (createCommand): Sleep some seconds after request failed. If tracker request fails more than value of PREF_TRACKER_MAX_TRIES, then abort tracker request.pull/1/head
parent
ad7078db28
commit
8eeeac7192
|
@ -79,7 +79,7 @@ void AbstractDiskWriter::openExistingFile(const string& filename, int64_t totalL
|
|||
throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), "file not found");
|
||||
}
|
||||
|
||||
if((fd = open(filename.c_str(), O_RDWR, S_IRUSR|S_IWUSR)) < 0) {
|
||||
if((fd = open(filename.c_str(), O_RDWR, OPEN_MODE)) < 0) {
|
||||
throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), strerror(errno));
|
||||
}
|
||||
if(f.size() < totalLength) {
|
||||
|
@ -99,7 +99,7 @@ void AbstractDiskWriter::createFile(const string& filename, int32_t addFlags) {
|
|||
// if(filename.empty()) {
|
||||
// filename = "index.html";
|
||||
// }
|
||||
if((fd = open(filename.c_str(), O_CREAT|O_RDWR|O_TRUNC|addFlags, S_IRUSR|S_IWUSR)) < 0) {
|
||||
if((fd = open(filename.c_str(), O_CREAT|O_RDWR|O_TRUNC|addFlags, OPEN_MODE)) < 0) {
|
||||
throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), strerror(errno));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ void Directory::createDir(const string& parentDir, bool recursive) const {
|
|||
throw new DlAbortEx(EX_NOT_DIRECTORY, path.c_str());
|
||||
}
|
||||
} else {
|
||||
if(mkdir(path.c_str(), S_IRUSR|S_IWUSR|S_IXUSR) == -1) {
|
||||
if(mkdir(path.c_str(), OPEN_MODE) == -1) {
|
||||
throw new DlAbortEx(EX_MAKE_DIR, path.c_str(), strerror(errno));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,14 +98,13 @@ bool File::mkdirs() {
|
|||
if(Util::startsWith(name, "/")) {
|
||||
accDir = "/";
|
||||
}
|
||||
mode_t mode = S_IRUSR|S_IWUSR|S_IXUSR;
|
||||
for(Strings::const_iterator itr = dirs.begin(); itr != dirs.end();
|
||||
itr++, accDir += "/") {
|
||||
accDir += *itr;
|
||||
if(File(accDir).isDir()) {
|
||||
continue;
|
||||
}
|
||||
if(mkdir(accDir.c_str(), mode) == -1) {
|
||||
if(mkdir(accDir.c_str(), OPEN_MODE) == -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ bool PeerAbstractCommand::execute() {
|
|||
}
|
||||
return executeInternal();
|
||||
} catch(RecoverableException* err) {
|
||||
logger->error(MSG_DOWNLOAD_ABORTED, err, cuid);
|
||||
logger->debug(MSG_DOWNLOAD_ABORTED, err, cuid);
|
||||
logger->debug("CUID#%d - Peer %s:%d banned.",
|
||||
cuid, peer->ipaddr.c_str(), peer->port);
|
||||
onAbort(err);
|
||||
|
|
|
@ -72,10 +72,25 @@ public:
|
|||
bool isTorrent;
|
||||
|
||||
RequestGroup(const Strings& uris, const Option* option):
|
||||
_uris(uris), _segmentMan(0), _segmentManFactory(new DefaultSegmentManFactory(option)), _option(option), logger(LogFactory::getInstance()), _chunkChecksum(0), numConnection(0), isTorrent(false) {}
|
||||
_hintTotalLength(0),
|
||||
_uris(uris),
|
||||
_segmentMan(0),
|
||||
_segmentManFactory(new DefaultSegmentManFactory(option)),
|
||||
_option(option),
|
||||
logger(LogFactory::getInstance()),
|
||||
_chunkChecksum(0),
|
||||
numConnection(0),
|
||||
isTorrent(false) {}
|
||||
|
||||
RequestGroup(const string& uri, const Option* option):
|
||||
_segmentMan(0), _segmentManFactory(new DefaultSegmentManFactory(option)), _option(option), logger(LogFactory::getInstance()), _chunkChecksum(0), numConnection(0), isTorrent(false)
|
||||
_hintTotalLength(0),
|
||||
_segmentMan(0),
|
||||
_segmentManFactory(new DefaultSegmentManFactory(option)),
|
||||
_option(option),
|
||||
logger(LogFactory::getInstance()),
|
||||
_chunkChecksum(0),
|
||||
numConnection(0),
|
||||
isTorrent(false)
|
||||
{
|
||||
_uris.push_back(uri);
|
||||
}
|
||||
|
|
|
@ -83,6 +83,17 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
|
|||
}
|
||||
}
|
||||
|
||||
Commands RequestGroupMan::getInitialCommands(DownloadEngine* e) const
|
||||
{
|
||||
Commands commands;
|
||||
for(RequestGroups::const_iterator itr = _requestGroups.begin();
|
||||
itr != _requestGroups.end(); ++itr) {
|
||||
(*itr)->initSegmentMan();
|
||||
commands.push_back((*itr)->getNextCommand(e, 1).front());
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
void RequestGroupMan::showDownloadResults(ostream& o) const
|
||||
{
|
||||
// Download Results:
|
||||
|
|
|
@ -102,16 +102,7 @@ public:
|
|||
return totalLength;
|
||||
}
|
||||
|
||||
Commands getInitialCommands(DownloadEngine* e) const
|
||||
{
|
||||
Commands commands;
|
||||
for(RequestGroups::const_iterator itr = _requestGroups.begin();
|
||||
itr != _requestGroups.end(); ++itr) {
|
||||
(*itr)->initSegmentMan();
|
||||
commands.push_back((*itr)->getNextCommand(e, 1).front());
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
Commands getInitialCommands(DownloadEngine* e) const;
|
||||
|
||||
void removeStoppedGroup();
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ bool TrackerWatcherCommand::execute() {
|
|||
|
||||
Command* TrackerWatcherCommand::createCommand() {
|
||||
Command* command = 0;
|
||||
|
||||
if(btAnnounce->isAnnounceReady()) {
|
||||
command = createRequestCommand(btAnnounce->getAnnounceUrl());
|
||||
btAnnounce->announceStart(); // inside it, trackers++.
|
||||
|
@ -72,11 +73,13 @@ Command* TrackerWatcherCommand::createCommand() {
|
|||
e->_requestGroupMan->removeStoppedGroup();
|
||||
if(btAnnounce->isAllAnnounceFailed()) {
|
||||
btAnnounce->resetAnnounce();
|
||||
// sleep a few seconds.
|
||||
return 0;
|
||||
} else if(btAnnounce->isAnnounceReady()) {
|
||||
command =
|
||||
new SleepCommand(cuid, e,
|
||||
createRequestCommand(btAnnounce->getAnnounceUrl()),
|
||||
e->option->getAsInt(PREF_RETRY_WAIT));
|
||||
btAnnounce->announceStart(); // inside it, tracker++.
|
||||
}
|
||||
}
|
||||
return command;
|
||||
|
@ -94,7 +97,6 @@ Command* TrackerWatcherCommand::createRequestCommand(const string& url)
|
|||
logger->error("CUID#%d - Cannot create tracker request.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
logger->info("CUID#%d - Creating new tracker request command #%d", cuid,
|
||||
commands.front()->getCuid());
|
||||
return commands.front();
|
||||
|
|
|
@ -324,10 +324,10 @@ void Util::rangedFileCopy(const string& dest, const string& src, long long int s
|
|||
int destFd = -1;
|
||||
int srcFd = -1;
|
||||
try {
|
||||
if((destFd = open(dest.c_str(), O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR)) == -1) {
|
||||
if((destFd = open(dest.c_str(), O_CREAT|O_WRONLY|O_TRUNC, OPEN_MODE)) == -1) {
|
||||
throw new DlAbortEx(EX_FILE_OPEN, dest.c_str(), strerror(errno));
|
||||
}
|
||||
if((srcFd = open(src.c_str(), O_RDONLY, S_IRUSR|S_IWUSR)) == -1) {
|
||||
if((srcFd = open(src.c_str(), O_RDONLY, OPEN_MODE)) == -1) {
|
||||
throw new DlAbortEx(EX_FILE_OPEN, src.c_str(), strerror(errno));
|
||||
}
|
||||
if(lseek(srcFd, srcOffset, SEEK_SET) != srcOffset) {
|
||||
|
@ -496,7 +496,7 @@ void Util::fileChecksum(const string& filename, unsigned char* digest,
|
|||
char buf[BUFLEN];
|
||||
|
||||
int fd;
|
||||
if((fd = open(filename.c_str(), O_RDWR, S_IRUSR|S_IWUSR)) < 0) {
|
||||
if((fd = open(filename.c_str(), O_RDWR, OPEN_MODE)) < 0) {
|
||||
throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), strerror(errno));
|
||||
}
|
||||
while(1) {
|
||||
|
|
|
@ -78,4 +78,6 @@ public:
|
|||
typedef deque<string> Strings;
|
||||
typedef deque<int32_t> Integers;
|
||||
|
||||
#define OPEN_MODE S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
|
||||
|
||||
#endif // _D_COMMON_H_
|
||||
|
|
Loading…
Reference in New Issue