diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-27 08:04:43 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-27 08:04:43 -0500 |
commit | ad413ebf14fb097ebe663676003854accdcc9958 (patch) | |
tree | af48fbf418ff264bf2475046159edaaea8d826bc /hscript/disk.cc | |
parent | 1fdc18eb819b85cf54d80418892ac3dc1ad5a05c (diff) | |
download | horizon-ad413ebf14fb097ebe663676003854accdcc9958.tar.gz horizon-ad413ebf14fb097ebe663676003854accdcc9958.tar.bz2 horizon-ad413ebf14fb097ebe663676003854accdcc9958.tar.xz horizon-ad413ebf14fb097ebe663676003854accdcc9958.zip |
hscript: Use boost::filesystem everywhere convenient
Diffstat (limited to 'hscript/disk.cc')
-rw-r--r-- | hscript/disk.cc | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/hscript/disk.cc b/hscript/disk.cc index c02d4c8..784db24 100644 --- a/hscript/disk.cc +++ b/hscript/disk.cc @@ -17,10 +17,11 @@ #ifdef HAS_INSTALL_ENV # include <assert.h> /* assert */ # include <blkid/blkid.h> /* blkid_get_tag_value */ +# include <boost/filesystem.hpp> # include <libudev.h> /* udev_* */ # include <parted/parted.h> /* ped_* */ # include <sys/mount.h> /* mount */ -# include <sys/stat.h> /* mkdir, stat */ +# include <sys/stat.h> /* stat */ # include <sys/types.h> /* S_* */ # include <unistd.h> /* access */ #endif /* HAS_INSTALL_ENV */ @@ -29,6 +30,9 @@ using namespace Horizon::Keys; +namespace fs = boost::filesystem; +using boost::system::error_code; + #ifdef HAS_INSTALL_ENV /*! Determine if _block is a valid block device. @@ -424,7 +428,7 @@ bool Partition::execute(ScriptOptions) const { Key *LVMPhysical::parseFromData(const std::string &data, int lineno, - int *errors, int *warnings) { + int *errors, int *) { if(data.size() < 6 || data.substr(0, 5) != "/dev/") { if(errors) *errors += 1; output_error("installfile:" + std::to_string(lineno), @@ -432,12 +436,6 @@ Key *LVMPhysical::parseFromData(const std::string &data, int lineno, return nullptr; } - /*if(access(data.c_str(), F_OK) != 0) { - if(warnings) *warnings += 1; - output_warning("installfile:" + std::to_string(lineno), - "lvm_pv: device may not exist"); - }*/ - return new LVMPhysical(lineno, data); } @@ -508,6 +506,9 @@ bool Mount::validate(ScriptOptions options) const { bool Mount::execute(ScriptOptions options) const { const std::string actual_mount = "/target" + this->mountpoint(); const char *fstype = nullptr; +#ifdef HAS_INSTALL_ENV + error_code ec; +#endif /* We have to get the filesystem for the node. */ if(options.test(Simulate)) { @@ -538,6 +539,15 @@ bool Mount::execute(ScriptOptions options) const { #ifdef HAS_INSTALL_ENV else { /* mount */ + if(!fs::exists(actual_mount, ec)) { + fs::create_directory(actual_mount, ec); + if(ec.failed()) { + output_error("installfile:" + std::to_string(this->lineno()), + "mount: failed to create target directory for " + + this->mountpoint(), ec.message()); + return false; + } + } if(mount(this->device().c_str(), actual_mount.c_str(), fstype, 0, this->options().c_str()) != 0) { output_warning("installfile:" + std::to_string(this->lineno()), @@ -574,9 +584,23 @@ bool Mount::execute(ScriptOptions options) const { #ifdef HAS_INSTALL_ENV else { if(this->mountpoint() == "/") { - /* failure of mkdir will be handled in the !fstab_f case */ - mkdir("/target/etc", - S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + fs::create_directory("/target/etc", ec); + if(ec.failed()) { + output_error("installfile:" + std::to_string(this->lineno()), + "mount: failed to create /etc for target", + ec.message()); + return false; + } + fs::permissions("/target/etc", + fs::perms::owner_all | + fs::perms::group_read | fs::perms::group_exe | + fs::perms::others_read | fs::perms::others_exe, + ec); + if(ec.failed()) { + output_warning("installfile:" + std::to_string(this->lineno()), + "mount: failed to set permissions for target /etc", + ec.message()); + } } std::ofstream fstab_f("/target/etc/fstab"); if(!fstab_f) { |