Skip to content

Commit

Permalink
CreateDirectory: use /sbin/mount on macOS (#1162)
Browse files Browse the repository at this point in the history
* CreateDirectory: use /sbin/mount on macOS

Some users report `mount` not being found in PATH when using
Terminal.app (even though I can't reproduce this).

* CreateDirectory: get rid of some more cfg target_os
  • Loading branch information
cole-h authored Sep 11, 2024
1 parent b1d9772 commit 24116bc
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/action/base/create_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::{Path, PathBuf};

use nix::unistd::{chown, Group, User};

use target_lexicon::OperatingSystem;
use tokio::fs::{create_dir_all, remove_dir_all, remove_file};
use tokio::process::Command;
use tracing::{span, Span};
Expand Down Expand Up @@ -297,13 +298,20 @@ async fn path_is_mountpoint(path: &Path) -> Result<bool, ActionErrorKind> {
None => return Err(ActionErrorKind::PathNoneString(path.to_path_buf())),
};

let mut mount_command = Command::new("mount");
mount_command.process_group(0);
let mut mount_command = match OperatingSystem::host() {
OperatingSystem::MacOSX { .. } | OperatingSystem::Darwin => {
let mut cmd = Command::new("/sbin/mount");
cmd.arg("-d"); // `-d` means `--dry-run`
cmd
},
_ => {
let mut cmd = Command::new("mount");
cmd.arg("-f"); // `-f` means `--fake` not `--force`
cmd
},
};

#[cfg(target_os = "macos")]
mount_command.arg("-d"); // `-d` means `--dry-run`
#[cfg(target_os = "linux")]
mount_command.arg("-f"); // `-f` means `--fake` not `--force`
mount_command.process_group(0);

let output = execute_command(&mut mount_command).await?;
let output_string = String::from_utf8(output.stdout).map_err(ActionErrorKind::FromUtf8)?;
Expand All @@ -318,12 +326,13 @@ async fn path_is_mountpoint(path: &Path) -> Result<bool, ActionErrorKind> {
Some(destination_and_options) => destination_and_options,
None => continue,
};
// Each line on Linux looks like `portal on /run/user/1000/doc type fuse.portal (rw,nosuid,nodev,relatime,user_id=1000,group_id=100)`
#[cfg(target_os = "linux")]
let split_token = "type";
// Each line on MacOS looks like `/dev/disk3s6 on /System/Volumes/VM (apfs, local, noexec, journaled, noatime, nobrowse)`
#[cfg(target_os = "macos")]
let split_token = "(";

let split_token = match OperatingSystem::host() {
// Each line on MacOS looks like `/dev/disk3s6 on /System/Volumes/VM (apfs, local, noexec, journaled, noatime, nobrowse)`
OperatingSystem::MacOSX { .. } | OperatingSystem::Darwin => "(",
// Each line on Linux looks like `portal on /run/user/1000/doc type fuse.portal (rw,nosuid,nodev,relatime,user_id=1000,group_id=100)`
_ => "type",
};

if let Some(mount_path) = destination_and_options.rsplit(split_token).last() {
let trimmed = mount_path.trim();
Expand Down

0 comments on commit 24116bc

Please sign in to comment.