diff --git a/support/src/utils/unix.cpp b/support/src/utils/unix.cpp index 69f488a..2b2f2c1 100644 --- a/support/src/utils/unix.cpp +++ b/support/src/utils/unix.cpp @@ -311,11 +311,24 @@ auto use_getpwuid(uid_t uid, passwd_callback_t callback) -> result { #if defined(PROJECT_ENABLE_PUGIXML) auto generate_launchd_plist(const plist_cfg &cfg, bool overwrite_existing) -> bool { + FIFTHGRID_USES_FUNCTION_NAME(); + auto file = utils::path::combine(cfg.plist_path, {cfg.label + ".plist"}); if (utils::file::file{file}.exists() && not overwrite_existing) { return true; } + auto parent_directory = utils::path::get_parent_path(file); + if (not utils::file::directory{parent_directory}.create_directory()) { + utils::error::handle_error(function_name, + utils::error::create_error_message({ + "failed to create plist parent directory", + parent_directory, + std::to_string(errno), + })); + return false; + } + pugi::xml_document doc; auto decl = doc.append_child(pugi::node_declaration); decl.append_attribute("version") = "1.0"; @@ -370,26 +383,24 @@ auto generate_launchd_plist(const plist_cfg &cfg, bool overwrite_existing) #if defined(PROJECT_ENABLE_SPDLOG) || defined(PROJECT_ENABLE_FMT) auto launchctl_command(std::string_view label, launchctl_type type) -> int { + auto launch_agents_dir = utils::path::combine("~", { + "Library", + "LaunchAgents", + }); switch (type) { case launchctl_type::bootout: return system( fmt::format("launchctl bootout gui/{} '{}' 1>/dev/null 2>&1", getuid(), - utils::path::combine("~", - { - "/Library/LaunchAgents", - fmt::format("{}.plist", label), - })) + utils::path::combine(launch_agents_dir, + {fmt::format("{}.plist", label)})) .c_str()); case launchctl_type::bootstrap: return system( fmt::format("launchctl bootstrap gui/{} '{}' 1>/dev/null 2>&1", getuid(), - utils::path::combine("~", - { - "/Library/LaunchAgents", - fmt::format("{}.plist", label), - })) + utils::path::combine(launch_agents_dir, + {fmt::format("{}.plist", label)})) .c_str()); case launchctl_type::kickstart: