From ecfd1f8ceece57ae9b46fec17dc70eb7422b9b57 Mon Sep 17 00:00:00 2001 From: fufesou Date: Sat, 9 May 2026 14:59:10 +0800 Subject: [PATCH] fix(update): refactor logs Signed-off-by: fufesou --- src/platform/macos.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 71696dde2..7bc7233ab 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -1101,13 +1101,26 @@ impl Drop for DmgGuard { } } +fn attach_dmg_failure_message( + dmg_path: &str, + mount_point: &str, + status: impl std::fmt::Display, +) -> String { + format!( + "Failed to attach DMG image at {dmg_path}: {status}. A stale mount at {mount_point} may remain from a previous update; detach it with `hdiutil detach {mount_point}` or restart and retry." + ) +} + fn attach_dmg(dmg_path: &str, mount_point: &'static str) -> ResultType { let status = Command::new("hdiutil") .args(&["attach", "-nobrowse", "-mountpoint", mount_point, dmg_path]) .status()?; if !status.success() { - bail!("Failed to attach DMG image at {}: {:?}", dmg_path, status); + bail!( + "{}", + attach_dmg_failure_message(dmg_path, mount_point, status) + ); } Ok(DmgGuard(mount_point)) @@ -1309,6 +1322,17 @@ mod tests { assert_eq!(mode, 0o700); std::fs::remove_file(file_path).unwrap(); } + + #[test] + fn test_attach_dmg_failure_message_mentions_stale_mount_point() { + let message = + attach_dmg_failure_message("/tmp/RustDesk.dmg", UPDATE_DMG_MOUNT_POINT, "failed"); + + assert!(message.contains("/tmp/RustDesk.dmg")); + assert!(message.contains(UPDATE_DMG_MOUNT_POINT)); + assert!(message.contains("stale mount")); + assert!(message.contains("hdiutil detach")); + } } #[inline]