Skip to content

Commit 0574968

Browse files
committed
Fix stale FUSE mount cleanup on macOS and Linux
1 parent 63e82cb commit 0574968

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bigedit"
3-
version = "0.1.13"
3+
version = "0.1.14"
44
edition = "2021"
55
description = "A streaming TUI editor for very large files"
66
authors = ["bigedit contributors"]

src/bin/fuse_daemon.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,33 @@ fn main() -> Result<()> {
476476
// Create symlink for cleaner access: filename.edited -> .filename.view/filename
477477
let symlink_path = parent.join(format!("{}.edited", base_name));
478478

479+
// Clean up any stale mount point from a previous crashed session
480+
if mount_point.exists() {
481+
// Try to unmount first (in case it's a stale FUSE mount)
482+
#[cfg(target_os = "macos")]
483+
{
484+
let _ = std::process::Command::new("umount")
485+
.arg(&mount_point)
486+
.output();
487+
// Also try diskutil unmount for macFUSE
488+
let _ = std::process::Command::new("diskutil")
489+
.args(["unmount", "force"])
490+
.arg(&mount_point)
491+
.output();
492+
}
493+
#[cfg(target_os = "linux")]
494+
{
495+
let _ = std::process::Command::new("fusermount")
496+
.args(["-u", "-z"]) // lazy unmount
497+
.arg(&mount_point)
498+
.output();
499+
}
500+
// Give it a moment to unmount
501+
std::thread::sleep(std::time::Duration::from_millis(100));
502+
// Now try to remove the directory
503+
let _ = std::fs::remove_dir(&mount_point);
504+
}
505+
479506
std::fs::create_dir_all(&mount_point)?;
480507

481508
// Create symlink (remove if exists first)
@@ -503,6 +530,16 @@ fn main() -> Result<()> {
503530

504531
// Mount the filesystem (this blocks until unmounted)
505532
let fs = PatchedFileFS::new(state);
533+
534+
#[cfg(target_os = "macos")]
535+
let options = vec![
536+
MountOption::RO,
537+
MountOption::FSName("bigedit".to_string()),
538+
MountOption::CUSTOM("volname=bigedit".to_string()),
539+
MountOption::CUSTOM("local".to_string()),
540+
];
541+
542+
#[cfg(not(target_os = "macos"))]
506543
let options = vec![
507544
MountOption::RO,
508545
MountOption::FSName("bigedit".to_string()),

0 commit comments

Comments
 (0)