From 3a2e83682ede18102caf267b2ab5f170f607d6d2 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 5 Aug 2025 19:01:29 -0500 Subject: [PATCH] refactor --- .../include/drives/fuse/fuse_base.hpp | 5 +++- .../src/drives/fuse/fuse_base.cpp | 29 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/repertory/librepertory/include/drives/fuse/fuse_base.hpp b/repertory/librepertory/include/drives/fuse/fuse_base.hpp index dbe84ced..b8404ac2 100644 --- a/repertory/librepertory/include/drives/fuse/fuse_base.hpp +++ b/repertory/librepertory/include/drives/fuse/fuse_base.hpp @@ -54,6 +54,9 @@ protected: bool atime_enabled_{true}; bool console_enabled_{true}; bool foreground_{false}; +#if defined(__APPLE__) + std::string label_; +#endif // defined(__APPLE__) std::optional forced_gid_; std::optional forced_uid_; std::optional forced_umask_; @@ -608,7 +611,7 @@ public: static void display_version_information(std::vector args); - static auto unmount(const std::string &mount_location) -> int; + auto unmount(const std::string &mount_location) -> int; [[nodiscard]] auto get_mount_location() const -> std::string { return mount_location_; diff --git a/repertory/librepertory/src/drives/fuse/fuse_base.cpp b/repertory/librepertory/src/drives/fuse/fuse_base.cpp index eaf92cc9..cabfc52b 100644 --- a/repertory/librepertory/src/drives/fuse/fuse_base.cpp +++ b/repertory/librepertory/src/drives/fuse/fuse_base.cpp @@ -433,6 +433,8 @@ auto fuse_base::mount([[maybe_unused]] std::vector orig_args, } #if defined(__APPLE__) + label_ = std::format("com.fifthgrid.blockstorage.repertory.{}.{}", + provider_type_to_string(prov), unique_id); if (not foreground_) { if (not utils::file::change_to_process_directory()) { std::cerr << "Failed to change to process directory" << std::endl; @@ -442,16 +444,14 @@ auto fuse_base::mount([[maybe_unused]] std::vector orig_args, orig_args[0U] = utils::path::combine(".", {"repertory"}); orig_args.insert(std::next(orig_args.begin()), "-f"); - auto label = std::format("com.fifthgrid.blockstorage.repertory.{}.{}", - provider_type_to_string(prov), unique_id); if (not utils::generate_launchd_plist( - label, utils::path::combine("~", {"/Library/LaunchAgents"}), + label_, utils::path::combine("~", {"/Library/LaunchAgents"}), orig_args, utils::path::absolute("."), fmt::format("/tmp/repertory_{}_{}.out", provider_type_to_string(prov), unique_id), fmt::format("/tmp/repertory_{}_{}.err", provider_type_to_string(prov), unique_id))) { - std::cerr << fmt::format("Failed to generate plist|{}", label) + std::cerr << fmt::format("Failed to generate plist|{}", label_) << std::endl; return -1; } @@ -461,7 +461,7 @@ auto fuse_base::mount([[maybe_unused]] std::vector orig_args, utils::path::combine("~", { "/Library/LaunchAgents", - fmt::format("{}.plist", label), + fmt::format("{}.plist", label_), })) .c_str()); @@ -470,14 +470,14 @@ auto fuse_base::mount([[maybe_unused]] std::vector orig_args, utils::path::combine("~", { "/Library/LaunchAgents", - fmt::format("{}.plist", label), + fmt::format("{}.plist", label_), })) .c_str()); ret = system( - fmt::format("launchctl kickstart gui/{}/{}", getuid(), label).c_str()); + fmt::format("launchctl kickstart gui/{}/{}", getuid(), label_).c_str()); if (ret != 0) { - std::cerr << fmt::format("Failed to kickstart {}/{}", getuid(), label) + std::cerr << fmt::format("Failed to kickstart {}/{}", getuid(), label_) << std::endl; } @@ -920,6 +920,19 @@ auto fuse_base::unlink_(const char *path) -> int { auto fuse_base::unmount(const std::string &mount_location) -> int { #if defined(__APPLE__) + if (utils::file::file{ + utils::path::combine("~", {"/Library/LaunchAgents", label_})} + .exists()) { + return system( + fmt::format("launchctl bootout gui/{} '{}' 1>/dev/null 2>&1", getuid(), + utils::path::combine("~", + { + "/Library/LaunchAgents", + fmt::format("{}.plist", label_), + })) + .c_str()); + } + auto cmd = "umount \"" + mount_location + "\" >/dev/null 2>&1"; #else // !defined(__APPLE__) #if FUSE_USE_VERSION >= 30