summaryrefslogtreecommitdiff
path: root/hscript/disk.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-12 00:15:48 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-12 00:15:48 -0500
commit47558ea71d523fb71307d394be4bfad8da4664d8 (patch)
tree98016963b7a702acfbbe42da1e93a37b7286479f /hscript/disk.cc
parent736d495d637035783380973b69df043e0263e9d8 (diff)
downloadhorizon-47558ea71d523fb71307d394be4bfad8da4664d8.tar.gz
horizon-47558ea71d523fb71307d394be4bfad8da4664d8.tar.bz2
horizon-47558ea71d523fb71307d394be4bfad8da4664d8.tar.xz
horizon-47558ea71d523fb71307d394be4bfad8da4664d8.zip
hscript: Parse 'mount' key, add tests to ensure
Diffstat (limited to 'hscript/disk.cc')
-rw-r--r--hscript/disk.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/hscript/disk.cc b/hscript/disk.cc
index d491430..093c111 100644
--- a/hscript/disk.cc
+++ b/hscript/disk.cc
@@ -20,14 +20,46 @@ using namespace Horizon::Keys;
Key *Mount::parseFromData(const std::string data, int lineno, int *errors,
int *warnings) {
std::string dev, where, opt;
+ std::string::size_type where_pos, opt_pos;
+ bool any_failure = false;
+
long spaces = std::count(data.cbegin(), data.cend(), ' ');
if(spaces < 1 || spaces > 2) {
if(errors) *errors += 1;
+ /* Don't bother with any_failure, because this is immediately fatal. */
output_error("installfile:" + std::to_string(lineno),
"mount: expected either 2 or 3 elements, got: " +
std::to_string(spaces), "");
return nullptr;
}
+
+ where_pos = data.find_first_of(' ');
+ opt_pos = data.find_first_of(' ', where_pos);
+
+ dev = data.substr(0, where_pos);
+ where = data.substr(where_pos + 1, opt_pos);
+ if(opt_pos != std::string::npos) {
+ opt = data.substr(opt_pos);
+ }
+
+ if(dev.compare(0, 4, "/dev")) {
+ if(errors) *errors += 1;
+ any_failure = true;
+ output_error("installfile:" + std::to_string(lineno),
+ "mount: element 1: expected device node",
+ "'" + dev + "' is not a valid device node");
+ }
+
+ if(where[0] != '/') {
+ if(errors) *errors += 1;
+ any_failure = true;
+ output_error("installfile:" + std::to_string(lineno),
+ "mount: element 2: expected absolute path",
+ "'" + where + "' is not a valid absolute path");
+ }
+
+ if(any_failure) return nullptr;
+
return new Mount(lineno, dev, where, opt);
}