From 073961cfff9e249d92c240eabcf5d24a7b4a7bab Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Fri, 29 May 2020 09:53:03 -0500 Subject: hscript: Hostname: Create /etc if it doesn't exist Without this, errors are seen generating Alpine images. --- hscript/meta.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hscript/meta.cc b/hscript/meta.cc index ab8bdb5..dc17290 100644 --- a/hscript/meta.cc +++ b/hscript/meta.cc @@ -104,11 +104,19 @@ bool Hostname::execute() const { /* Runner.Execute.hostname.Write. */ output_info(pos, "hostname: write '" + actual + "' to /etc/hostname"); if(script->options().test(Simulate)) { + std::cout << "mkdir -p " << script->targetDirectory() << "/etc" + << std::endl; std::cout << "printf '%s' " << actual << " > " << script->targetDirectory() << "/etc/hostname" << std::endl; } #ifdef HAS_INSTALL_ENV else { + error_code ec; + fs::create_directory(script->targetDirectory() + "/etc", ec); + if(ec && ec.value() != EEXIST) { + output_error(pos, "hostname: could not create /etc", ec.message()); + return false; + } std::ofstream hostname_f(script->targetDirectory() + "/etc/hostname", std::ios_base::trunc); if(!hostname_f) { -- cgit v1.2.3-70-g09d2