summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hscript/CMakeLists.txt13
-rw-r--r--hscript/disk.cc17
-rw-r--r--hscript/meta.cc16
-rw-r--r--hscript/script.cc18
-rw-r--r--util/filesystem.hh15
5 files changed, 44 insertions, 35 deletions
diff --git a/hscript/CMakeLists.txt b/hscript/CMakeLists.txt
index d0c5473..e6e86b6 100644
--- a/hscript/CMakeLists.txt
+++ b/hscript/CMakeLists.txt
@@ -11,12 +11,19 @@ set(HSCRIPT_INCLUDE
script.hh
)
-find_package(Boost REQUIRED COMPONENTS filesystem)
-
add_library(hscript ${HSCRIPT_SOURCE})
target_compile_features(hscript PRIVATE cxx_nullptr)
target_compile_features(hscript PUBLIC cxx_unicode_literals)
-target_link_libraries(hscript ${BLKID_LIBRARIES} ${Boost_FILESYSTEM_LIBRARY} ${LIBUDEV_LIBRARIES} ${PARTED_LIBRARIES})
+if("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
+ set_property(TARGET hscript PROPERTY CXX_STANDARD 17)
+ SET(FS_LIBRARY stdc++fs)
+ add_definitions(-DFS_IS_STDCXX)
+ELSE()
+ find_package(Boost REQUIRED COMPONENTS filesystem)
+ SET(FS_LIBRARY ${Boost_FILESYSTEM_LIBRARY})
+ add_definitions(-DFS_IS_BOOST)
+ENDIF()
+target_link_libraries(hscript ${BLKID_LIBRARIES} ${FS_LIBRARY} ${LIBUDEV_LIBRARIES} ${PARTED_LIBRARIES})
install(TARGETS hscript DESTINATION lib)
install(FILES ${HSCRIPT_INCLUDE} DESTINATION include/hscript)
diff --git a/hscript/disk.cc b/hscript/disk.cc
index 784db24..f66c1e0 100644
--- a/hscript/disk.cc
+++ b/hscript/disk.cc
@@ -17,7 +17,7 @@
#ifdef HAS_INSTALL_ENV
# include <assert.h> /* assert */
# include <blkid/blkid.h> /* blkid_get_tag_value */
-# include <boost/filesystem.hpp>
+# include "util/filesystem.hh"
# include <libudev.h> /* udev_* */
# include <parted/parted.h> /* ped_* */
# include <sys/mount.h> /* mount */
@@ -30,10 +30,6 @@
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.
* @param key The key associated with this test.
@@ -541,7 +537,7 @@ bool Mount::execute(ScriptOptions options) const {
/* mount */
if(!fs::exists(actual_mount, ec)) {
fs::create_directory(actual_mount, ec);
- if(ec.failed()) {
+ if(ec) {
output_error("installfile:" + std::to_string(this->lineno()),
"mount: failed to create target directory for "
+ this->mountpoint(), ec.message());
@@ -585,7 +581,7 @@ bool Mount::execute(ScriptOptions options) const {
else {
if(this->mountpoint() == "/") {
fs::create_directory("/target/etc", ec);
- if(ec.failed()) {
+ if(ec) {
output_error("installfile:" + std::to_string(this->lineno()),
"mount: failed to create /etc for target",
ec.message());
@@ -593,10 +589,11 @@ bool Mount::execute(ScriptOptions options) const {
}
fs::permissions("/target/etc",
fs::perms::owner_all |
- fs::perms::group_read | fs::perms::group_exe |
- fs::perms::others_read | fs::perms::others_exe,
+ fs::perms::group_read | fs::perms::group_exec |
+ fs::perms::others_read | fs::perms::others_exec,
+ fs::perm_options::replace,
ec);
- if(ec.failed()) {
+ if(ec) {
output_warning("installfile:" + std::to_string(this->lineno()),
"mount: failed to set permissions for target /etc",
ec.message());
diff --git a/hscript/meta.cc b/hscript/meta.cc
index 304b9c1..d935ca4 100644
--- a/hscript/meta.cc
+++ b/hscript/meta.cc
@@ -16,7 +16,7 @@
#include <set>
#include <sstream>
#ifdef HAS_INSTALL_ENV
-# include <boost/filesystem.hpp>
+# include "util/filesystem.hh"
#endif /* HAS_INSTALL_ENV */
#include <unistd.h> /* access - used by tz code even in RT env */
#include "meta.hh"
@@ -24,9 +24,6 @@
using namespace Horizon::Keys;
-namespace fs = boost::filesystem;
-using boost::system::error_code;
-
Key *Hostname::parseFromData(const std::string &data, int lineno, int *errors,
int *) {
std::regex valid_re("[A-Za-z0-9-_.]*");
@@ -293,11 +290,8 @@ bool Language::execute(ScriptOptions opts) const {
<< this->value() << "\"" << std::endl;
lang_f.close();
- fs::permissions(lang_path,
- fs::perms::owner_all |
- fs::perms::group_read | fs::perms::group_exe |
- fs::perms::others_read | fs::perms::others_exe, ec);
- if(ec.failed()) {
+ fs::permissions(lang_path, rwxr_xr_x, ec);
+ if(ec) {
output_error("installfile:" + std::to_string(this->lineno()),
"language: could not set /etc/profile.d/language.sh "
"as executable", ec.message());
@@ -389,7 +383,7 @@ bool Timezone::execute(ScriptOptions opts) const {
error_code ec;
if(fs::exists(target_zi, ec)) {
fs::create_symlink(zi_path, "/target/etc/localtime", ec);
- if(ec.failed()) {
+ if(ec) {
output_error("installfile:" + std::to_string(this->lineno()),
"timezone: failed to create symbolic link",
ec.message());
@@ -400,7 +394,7 @@ bool Timezone::execute(ScriptOptions opts) const {
/* The target doesn't have tzdata installed. We copy the zoneinfo
* file from the Horizon environment to the target. */
fs::copy_file(zi_path, "/target/etc/localtime", ec);
- if(ec.failed()) {
+ if(ec) {
output_error("installfile:" + std::to_string(this->lineno()),
"timezone: failed to prepare target environment",
ec.message());
diff --git a/hscript/script.cc b/hscript/script.cc
index 1701657..5849296 100644
--- a/hscript/script.cc
+++ b/hscript/script.cc
@@ -12,7 +12,7 @@
#include <algorithm>
#include <assert.h>
-#include <boost/filesystem.hpp>
+#include "util/filesystem.hh"
#include <fstream>
#include <iostream>
#include <map>
@@ -34,9 +34,6 @@ typedef Horizon::Keys::Key *(*key_parse_fn)(const std::string &, int, int*, int*
using namespace Horizon::Keys;
-namespace fs = boost::filesystem;
-using boost::system::error_code;
-
const std::map<std::string, key_parse_fn> valid_keys = {
{"network", &Network::parseFromData},
{"hostname", &Hostname::parseFromData},
@@ -1013,9 +1010,8 @@ bool Script::execute() const {
} else {
fs::copy_file("/tmp/horizon/wpa_supplicant.conf",
"/target/etc/wpa_supplicant/wpa_supplicant.conf",
- fs::copy_option::overwrite_if_exists,
- ec);
- if(ec.failed()) {
+ fs_overwrite, ec);
+ if(ec) {
output_error("internal", "cannot save wireless networking "
"configuration to target", ec.message());
}
@@ -1088,16 +1084,16 @@ bool Script::execute() const {
if(do_wpa) {
fs::copy_file("/target/etc/wpa_supplicant/wpa_supplicant.conf",
"/etc/wpa_supplicant/wpa_supplicant.conf",
- fs::copy_option::overwrite_if_exists, ec);
- if(ec.failed()) {
+ fs_overwrite, ec);
+ if(ec) {
output_error("internal", "cannot use wireless configuration "
"during installation", ec.message());
EXECUTE_FAILURE("net");
}
}
fs::copy_file("/target/etc/conf.d/net", "/etc/conf.d/net",
- fs::copy_option::overwrite_if_exists, ec);
- if(ec.failed()) {
+ fs_overwrite, ec);
+ if(ec) {
output_error("internal", "cannot use networking configuration "
"during installation", ec.message());
EXECUTE_FAILURE("net");
diff --git a/util/filesystem.hh b/util/filesystem.hh
new file mode 100644
index 0000000..08db437
--- /dev/null
+++ b/util/filesystem.hh
@@ -0,0 +1,15 @@
+#if defined(FS_IS_BOOST)
+# include <boost/filesystem.hpp>
+ namespace fs = boost::filesystem;
+ using boost::system::error_code;
+# define fs_overwrite fs::copy_option::overwrite_if_exists
+# define rwxr_xr_x fs::perms::owner_all | fs::perms::group_read | fs::perms::group_exe | fs::perms::others_read | fs::perms::others_exe
+#elif defined(FS_IS_STDCXX)
+# include <filesystem>
+ namespace fs = std::filesystem;
+ using std::error_code;
+# define fs_overwrite fs::copy_options::overwrite_existing
+# define rwxr_xr_x fs::perms::owner_all | fs::perms::group_read | fs::perms::group_exec | fs::perms::others_read | fs::perms::others_exec
+#else
+# error Missing <filesystem> implementation.
+#endif