mirror of https://github.com/aria2/aria2
2009-06-21 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
The default value of --dir option is the absolute path to the current directory. If getcwd() is failed, then it is ".", which is the same value with old implementation. This change is necessary because after daemon() call, the current working directory is changed to /. * src/File.cc * src/File.h * src/OptionHandlerFactory.cc * src/option_processing.ccpull/1/head
parent
3636345a25
commit
8d4f29d302
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
2009-06-21 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
The default value of --dir option is the absolute path to the
|
||||
current directory. If getcwd() is failed, then it is ".", which is
|
||||
the same value with old implementation. This change is necessary
|
||||
because after daemon() call, the current working directory is
|
||||
changed to /.
|
||||
* src/File.cc
|
||||
* src/File.h
|
||||
* src/OptionHandlerFactory.cc
|
||||
* src/option_processing.cc
|
||||
|
||||
2009-06-21 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Call daemon() with arguments(0,0), which means daemon() changes
|
||||
|
|
18
src/File.cc
18
src/File.cc
|
@ -37,6 +37,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <utime.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <deque>
|
||||
#include <cstring>
|
||||
|
@ -44,6 +45,7 @@
|
|||
|
||||
#include "Util.h"
|
||||
#include "A2STR.h"
|
||||
#include "array_fun.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -201,4 +203,20 @@ Time File::getModifiedTime()
|
|||
return Time(fstat.st_mtime);
|
||||
}
|
||||
|
||||
std::string File::getCurrentDir()
|
||||
{
|
||||
size_t buflen = 256;
|
||||
while(buflen <= 2048) {
|
||||
array_ptr<char> buf(new char[buflen]);
|
||||
if(getcwd(buf, buflen)) {
|
||||
return std::string(buf);
|
||||
} else if(errno == ERANGE) {
|
||||
buflen *= 2;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return A2STR::DOT_C;
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -109,6 +109,11 @@ public:
|
|||
bool utime(const Time& actime, const Time& modtime) const;
|
||||
|
||||
Time getModifiedTime();
|
||||
|
||||
// Returns the current working directory. If the current working
|
||||
// directory cannot be retrieved or its length is larger than 2048,
|
||||
// returns ".".
|
||||
static std::string getCurrentDir();
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -141,7 +141,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
|||
SharedHandle<OptionHandler> op(new DefaultOptionHandler
|
||||
(PREF_DIR,
|
||||
TEXT_DIR,
|
||||
".",
|
||||
File::getCurrentDir(),
|
||||
A2STR::NIL,
|
||||
OptionHandler::REQ_ARG,
|
||||
'd'));
|
||||
|
|
|
@ -191,6 +191,11 @@ void option_processing(Option& op, std::deque<std::string>& uris,
|
|||
}
|
||||
#ifdef HAVE_DAEMON
|
||||
if(op.getAsBool(PREF_DAEMON)) {
|
||||
if(File::getCurrentDir() == ".") {
|
||||
std::cerr << "Failed to get the current working directory."
|
||||
<< " With -D option engaged,"
|
||||
<< " the default value of --dir option is /." << std::endl;
|
||||
}
|
||||
if(daemon(0, 0) < 0) {
|
||||
perror(MSG_DAEMON_FAILED);
|
||||
exit(DownloadResult::UNKNOWN_ERROR);
|
||||
|
|
Loading…
Reference in New Issue