mirror of https://github.com/aria2/aria2
Better error message when local file status cannot be retrieved
parent
c1a0b33515
commit
744a5a550d
10
src/File.cc
10
src/File.cc
|
@ -79,6 +79,16 @@ bool File::exists()
|
||||||
return fillStat(fstat) == 0;
|
return fillStat(fstat) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool File::exists(std::string &err)
|
||||||
|
{
|
||||||
|
a2_struct_stat fstat;
|
||||||
|
if (fillStat(fstat) != 0) {
|
||||||
|
err = fmt("Could not get file status: %s", strerror(errno));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool File::isFile()
|
bool File::isFile()
|
||||||
{
|
{
|
||||||
a2_struct_stat fstat;
|
a2_struct_stat fstat;
|
||||||
|
|
|
@ -70,6 +70,13 @@ public:
|
||||||
*/
|
*/
|
||||||
bool exists();
|
bool exists();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether the file or directory denoted by name exists. If
|
||||||
|
* file does not exist, or file status could not be retrieved, this
|
||||||
|
* function stores error message to |err|.
|
||||||
|
*/
|
||||||
|
bool exists(std::string& err);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests whether the file denoted by name is a regular file.
|
* Tests whether the file denoted by name is a regular file.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -551,7 +551,11 @@ void LocalFilePathOptionHandler::parseArg(Option& option,
|
||||||
auto path = util::replace(optarg, "${HOME}", util::getHomeDir());
|
auto path = util::replace(optarg, "${HOME}", util::getHomeDir());
|
||||||
if (mustExist_) {
|
if (mustExist_) {
|
||||||
File f(path);
|
File f(path);
|
||||||
if (!f.exists() || f.isDir()) {
|
std::string err;
|
||||||
|
if (!f.exists(err)) {
|
||||||
|
throw DL_ABORT_EX(err);
|
||||||
|
}
|
||||||
|
if (f.isDir()) {
|
||||||
throw DL_ABORT_EX(fmt(MSG_NOT_FILE, optarg.c_str()));
|
throw DL_ABORT_EX(fmt(MSG_NOT_FILE, optarg.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue