Skip to content

Commit 8684510

Browse files
committed
Improve compatibility with macfuse
Linking against fuse3 provided by macfuse results in a hang in some tests
1 parent a8cd42c commit 8684510

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/mnt/fuse3.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use super::fuse3_sys::{
33
fuse_session_unmount,
44
};
55
use super::{MountOption, with_fuse_args};
6+
use log::warn;
67
use std::{
78
ffi::{CString, c_void},
89
fs::File,
@@ -25,6 +26,7 @@ fn ensure_last_os_error() -> io::Error {
2526
#[derive(Debug)]
2627
pub struct Mount {
2728
fuse_session: *mut c_void,
29+
mountpoint: CString,
2830
}
2931
impl Mount {
3032
pub fn new(mnt: &Path, options: &[MountOption]) -> io::Result<(Arc<File>, Mount)> {
@@ -34,7 +36,10 @@ impl Mount {
3436
if fuse_session.is_null() {
3537
return Err(io::Error::last_os_error());
3638
}
37-
let mount = Mount { fuse_session };
39+
let mount = Mount {
40+
fuse_session,
41+
mountpoint: mnt.clone(),
42+
};
3843
let result = unsafe { fuse_session_mount(mount.fuse_session, mnt.as_ptr()) };
3944
if result != 0 {
4045
return Err(ensure_last_os_error());
@@ -53,9 +58,20 @@ impl Mount {
5358
}
5459
impl Drop for Mount {
5560
fn drop(&mut self) {
56-
unsafe {
57-
fuse_session_unmount(self.fuse_session);
58-
fuse_session_destroy(self.fuse_session);
61+
use std::io::ErrorKind::PermissionDenied;
62+
63+
if let Err(err) = super::libc_umount(&self.mountpoint) {
64+
// Linux always returns EPERM for non-root users. We have to let the
65+
// library go through the setuid-root "fusermount -u" to unmount.
66+
if err.kind() == PermissionDenied {
67+
#[cfg(target_os = "linux")]
68+
unsafe {
69+
fuse_session_unmount(self.fuse_session);
70+
fuse_session_destroy(self.fuse_session);
71+
return;
72+
}
73+
}
74+
warn!("umount failed with {:?}", err);
5975
}
6076
}
6177
}

src/mnt/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub mod mount_options;
1919
use fuse2_sys::fuse_args;
2020
#[cfg(any(test, not(feature = "libfuse")))]
2121
use std::fs::File;
22-
#[cfg(any(test, fuser_mount_impl = "pure-rust", fuser_mount_impl = "libfuse2"))]
2322
use std::io;
2423

2524
#[cfg(any(feature = "libfuse", test))]
@@ -53,10 +52,8 @@ pub use fuse_pure::Mount;
5352
pub use fuse2::Mount;
5453
#[cfg(fuser_mount_impl = "libfuse3")]
5554
pub use fuse3::Mount;
56-
#[cfg(not(fuser_mount_impl = "libfuse3"))]
5755
use std::ffi::CStr;
5856

59-
#[cfg(not(fuser_mount_impl = "libfuse3"))]
6057
#[inline]
6158
fn libc_umount(mnt: &CStr) -> io::Result<()> {
6259
#[cfg(any(

0 commit comments

Comments
 (0)