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");
|
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));
|
throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), strerror(errno));
|
||||||
}
|
}
|
||||||
if(f.size() < totalLength) {
|
if(f.size() < totalLength) {
|
||||||
|
@ -99,7 +99,7 @@ void AbstractDiskWriter::createFile(const string& filename, int32_t addFlags) {
|
||||||
// if(filename.empty()) {
|
// if(filename.empty()) {
|
||||||
// filename = "index.html";
|
// 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));
|
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());
|
throw new DlAbortEx(EX_NOT_DIRECTORY, path.c_str());
|
||||||
}
|
}
|
||||||
} else {
|
} 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));
|
throw new DlAbortEx(EX_MAKE_DIR, path.c_str(), strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,14 +98,13 @@ bool File::mkdirs() {
|
||||||
if(Util::startsWith(name, "/")) {
|
if(Util::startsWith(name, "/")) {
|
||||||
accDir = "/";
|
accDir = "/";
|
||||||
}
|
}
|
||||||
mode_t mode = S_IRUSR|S_IWUSR|S_IXUSR;
|
|
||||||
for(Strings::const_iterator itr = dirs.begin(); itr != dirs.end();
|
for(Strings::const_iterator itr = dirs.begin(); itr != dirs.end();
|
||||||
itr++, accDir += "/") {
|
itr++, accDir += "/") {
|
||||||
accDir += *itr;
|
accDir += *itr;
|
||||||
if(File(accDir).isDir()) {
|
if(File(accDir).isDir()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(mkdir(accDir.c_str(), mode) == -1) {
|
if(mkdir(accDir.c_str(), OPEN_MODE) == -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ bool PeerAbstractCommand::execute() {
|
||||||
}
|
}
|
||||||
return executeInternal();
|
return executeInternal();
|
||||||
} catch(RecoverableException* err) {
|
} 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.",
|
logger->debug("CUID#%d - Peer %s:%d banned.",
|
||||||
cuid, peer->ipaddr.c_str(), peer->port);
|
cuid, peer->ipaddr.c_str(), peer->port);
|
||||||
onAbort(err);
|
onAbort(err);
|
||||||
|
|
|
@ -72,10 +72,25 @@ public:
|
||||||
bool isTorrent;
|
bool isTorrent;
|
||||||
|
|
||||||
RequestGroup(const Strings& uris, const Option* option):
|
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):
|
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);
|
_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
|
void RequestGroupMan::showDownloadResults(ostream& o) const
|
||||||
{
|
{
|
||||||
// Download Results:
|
// Download Results:
|
||||||
|
|
|
@ -102,16 +102,7 @@ public:
|
||||||
return totalLength;
|
return totalLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands getInitialCommands(DownloadEngine* e) const
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeStoppedGroup();
|
void removeStoppedGroup();
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,7 @@ bool TrackerWatcherCommand::execute() {
|
||||||
|
|
||||||
Command* TrackerWatcherCommand::createCommand() {
|
Command* TrackerWatcherCommand::createCommand() {
|
||||||
Command* command = 0;
|
Command* command = 0;
|
||||||
|
|
||||||
if(btAnnounce->isAnnounceReady()) {
|
if(btAnnounce->isAnnounceReady()) {
|
||||||
command = createRequestCommand(btAnnounce->getAnnounceUrl());
|
command = createRequestCommand(btAnnounce->getAnnounceUrl());
|
||||||
btAnnounce->announceStart(); // inside it, trackers++.
|
btAnnounce->announceStart(); // inside it, trackers++.
|
||||||
|
@ -72,11 +73,13 @@ Command* TrackerWatcherCommand::createCommand() {
|
||||||
e->_requestGroupMan->removeStoppedGroup();
|
e->_requestGroupMan->removeStoppedGroup();
|
||||||
if(btAnnounce->isAllAnnounceFailed()) {
|
if(btAnnounce->isAllAnnounceFailed()) {
|
||||||
btAnnounce->resetAnnounce();
|
btAnnounce->resetAnnounce();
|
||||||
// sleep a few seconds.
|
return 0;
|
||||||
|
} else if(btAnnounce->isAnnounceReady()) {
|
||||||
command =
|
command =
|
||||||
new SleepCommand(cuid, e,
|
new SleepCommand(cuid, e,
|
||||||
createRequestCommand(btAnnounce->getAnnounceUrl()),
|
createRequestCommand(btAnnounce->getAnnounceUrl()),
|
||||||
e->option->getAsInt(PREF_RETRY_WAIT));
|
e->option->getAsInt(PREF_RETRY_WAIT));
|
||||||
|
btAnnounce->announceStart(); // inside it, tracker++.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return command;
|
return command;
|
||||||
|
@ -94,7 +97,6 @@ Command* TrackerWatcherCommand::createRequestCommand(const string& url)
|
||||||
logger->error("CUID#%d - Cannot create tracker request.");
|
logger->error("CUID#%d - Cannot create tracker request.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger->info("CUID#%d - Creating new tracker request command #%d", cuid,
|
logger->info("CUID#%d - Creating new tracker request command #%d", cuid,
|
||||||
commands.front()->getCuid());
|
commands.front()->getCuid());
|
||||||
return commands.front();
|
return commands.front();
|
||||||
|
|
|
@ -324,10 +324,10 @@ void Util::rangedFileCopy(const string& dest, const string& src, long long int s
|
||||||
int destFd = -1;
|
int destFd = -1;
|
||||||
int srcFd = -1;
|
int srcFd = -1;
|
||||||
try {
|
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));
|
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));
|
throw new DlAbortEx(EX_FILE_OPEN, src.c_str(), strerror(errno));
|
||||||
}
|
}
|
||||||
if(lseek(srcFd, srcOffset, SEEK_SET) != srcOffset) {
|
if(lseek(srcFd, srcOffset, SEEK_SET) != srcOffset) {
|
||||||
|
@ -496,7 +496,7 @@ void Util::fileChecksum(const string& filename, unsigned char* digest,
|
||||||
char buf[BUFLEN];
|
char buf[BUFLEN];
|
||||||
|
|
||||||
int fd;
|
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));
|
throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), strerror(errno));
|
||||||
}
|
}
|
||||||
while(1) {
|
while(1) {
|
||||||
|
|
|
@ -78,4 +78,6 @@ public:
|
||||||
typedef deque<string> Strings;
|
typedef deque<string> Strings;
|
||||||
typedef deque<int32_t> Integers;
|
typedef deque<int32_t> Integers;
|
||||||
|
|
||||||
|
#define OPEN_MODE S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
|
||||||
|
|
||||||
#endif // _D_COMMON_H_
|
#endif // _D_COMMON_H_
|
||||||
|
|
Loading…
Reference in New Issue