remove launchd entry on unmount
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
This commit is contained in:
@@ -936,11 +936,14 @@ auto fuse_base::unlink_(const char *path) -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto fuse_base::unmount(const std::string &mount_location) -> int {
|
auto fuse_base::unmount(const std::string &mount_location) -> int {
|
||||||
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
if (utils::file::file{
|
if (not utils::remove_launchd_plist(
|
||||||
utils::path::combine("~", {"/Library/LaunchAgents", label_})}
|
utils::path::combine("~", {"/Library/LaunchAgents"}), label_, true)) {
|
||||||
.exists()) {
|
utils::error::raise_error(
|
||||||
return utils::launchctl_command(label_, utils::launchctl_type::bootout);
|
function_name,
|
||||||
|
fmt::format("failed to remove launchd entry|label|{}", label_));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto cmd = "umount \"" + mount_location + "\" >/dev/null 2>&1";
|
auto cmd = "umount \"" + mount_location + "\" >/dev/null 2>&1";
|
||||||
|
@@ -304,9 +304,6 @@ void mgmt_app_config::set_auto_start(bool auto_start) {
|
|||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
const auto *label = "com.fifthgrid.blockstorage.repertory.ui";
|
const auto *label = "com.fifthgrid.blockstorage.repertory.ui";
|
||||||
auto plist_path = utils::path::combine("~", {"/Library/LaunchAgents"});
|
auto plist_path = utils::path::combine("~", {"/Library/LaunchAgents"});
|
||||||
auto file = utils::file::file{
|
|
||||||
utils::path::combine(plist_path, {label}),
|
|
||||||
};
|
|
||||||
if (auto_start) {
|
if (auto_start) {
|
||||||
utils::plist_cfg cfg{};
|
utils::plist_cfg cfg{};
|
||||||
cfg.args = {
|
cfg.args = {
|
||||||
@@ -330,13 +327,12 @@ void mgmt_app_config::set_auto_start(bool auto_start) {
|
|||||||
function_name, utils::get_last_error_code(),
|
function_name, utils::get_last_error_code(),
|
||||||
"failed to create auto-start entry|name|repertory");
|
"failed to create auto-start entry|name|repertory");
|
||||||
}
|
}
|
||||||
} else if (file.remove()) {
|
} else if (utils::remove_launchd_plist(plist_path, label, false)) {
|
||||||
utils::error::handle_info(function_name,
|
utils::error::handle_info(function_name,
|
||||||
"removed auto-start entry|name|repertory");
|
"removed auto-start entry|name|repertory");
|
||||||
} else {
|
} else {
|
||||||
utils::error::raise_error(
|
utils::error::raise_error(
|
||||||
function_name, utils::get_last_error_code(),
|
function_name, "failed to remove auto-start entry|name|repertory");
|
||||||
"failed to remove auto-start entry|name|repertory");
|
|
||||||
}
|
}
|
||||||
#endif // defined(__APPLE__)
|
#endif // defined(__APPLE__)
|
||||||
} else {
|
} else {
|
||||||
|
@@ -99,8 +99,14 @@ void set_last_error_code(int error_code);
|
|||||||
-> bool;
|
-> bool;
|
||||||
#endif // defined(PROJECT_ENABLE_PUGIXML)
|
#endif // defined(PROJECT_ENABLE_PUGIXML)
|
||||||
|
|
||||||
|
#if defined(PROJECT_ENABLE_FMT)
|
||||||
[[nodiscard]] auto launchctl_command(std::string_view label,
|
[[nodiscard]] auto launchctl_command(std::string_view label,
|
||||||
launchctl_type type) -> int;
|
launchctl_type type) -> int;
|
||||||
|
|
||||||
|
[[nodiscard]] auto remove_launchd_plist(std::string_view plist_path,
|
||||||
|
std::string_view label,
|
||||||
|
bool should_bootout) -> bool;
|
||||||
|
#endif // defined(PROJECT_ENABLE_FMT)
|
||||||
#endif // defined(__APPLE__)
|
#endif // defined(__APPLE__)
|
||||||
|
|
||||||
// template implementations
|
// template implementations
|
||||||
|
@@ -368,6 +368,7 @@ auto generate_launchd_plist(const plist_cfg &cfg, bool overwrite_existing)
|
|||||||
}
|
}
|
||||||
#endif // defined(PROJECT_ENABLE_PUGIXML)
|
#endif // defined(PROJECT_ENABLE_PUGIXML)
|
||||||
|
|
||||||
|
#if defined(PROJECT_ENABLE_FMT)
|
||||||
auto launchctl_command(std::string_view label, launchctl_type type) -> int {
|
auto launchctl_command(std::string_view label, launchctl_type type) -> int {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case launchctl_type::bootout:
|
case launchctl_type::bootout:
|
||||||
@@ -398,6 +399,25 @@ auto launchctl_command(std::string_view label, launchctl_type type) -> int {
|
|||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto remove_launchd_plist(std::string_view plist_path, std::string_view label,
|
||||||
|
bool should_bootout) -> bool {
|
||||||
|
auto file = utils::file::file{
|
||||||
|
utils::path::combine(plist_path, {label + ".plist"}),
|
||||||
|
};
|
||||||
|
if (not file.exists()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto res =
|
||||||
|
should_bootout ? launchctl_command(label, launchctl_type::bootout) : 0;
|
||||||
|
if (not file.remove()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res == 0;
|
||||||
|
}
|
||||||
|
#endif // defined(PROJECT_ENABLE_FMT)
|
||||||
#endif // defined(__APPLE__)
|
#endif // defined(__APPLE__)
|
||||||
} // namespace repertory::utils
|
} // namespace repertory::utils
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user