summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/File.cc10
-rw-r--r--src/File.h7
-rw-r--r--src/OptionHandlerImpl.cc6
3 files changed, 22 insertions, 1 deletions
diff --git a/src/File.cc b/src/File.cc
index 3ee6c47a..14189ef0 100644
--- a/src/File.cc
+++ b/src/File.cc
@@ -79,6 +79,16 @@ bool File::exists()
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()
{
a2_struct_stat fstat;
diff --git a/src/File.h b/src/File.h
index 1e659022..6d304640 100644
--- a/src/File.h
+++ b/src/File.h
@@ -71,6 +71,13 @@ public:
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.
*/
bool isFile();
diff --git a/src/OptionHandlerImpl.cc b/src/OptionHandlerImpl.cc
index 6be23492..6214e84b 100644
--- a/src/OptionHandlerImpl.cc
+++ b/src/OptionHandlerImpl.cc
@@ -551,7 +551,11 @@ void LocalFilePathOptionHandler::parseArg(Option& option,
auto path = util::replace(optarg, "${HOME}", util::getHomeDir());
if (mustExist_) {
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()));
}
}