refactor
All checks were successful
BlockStorage/repertory_mac/pipeline/head This commit looks good

This commit is contained in:
2025-08-05 19:01:29 -05:00
parent b28496c7b6
commit 3a2e83682e
2 changed files with 25 additions and 9 deletions

View File

@@ -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<gid_t> forced_gid_;
std::optional<uid_t> forced_uid_;
std::optional<mode_t> forced_umask_;
@@ -608,7 +611,7 @@ public:
static void display_version_information(std::vector<const char *> 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_;

View File

@@ -433,6 +433,8 @@ auto fuse_base::mount([[maybe_unused]] std::vector<std::string> 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<std::string> 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<std::string> 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<std::string> 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