From 52054c916d812acaa5e07238c3c72e0e73f797cd Mon Sep 17 00:00:00 2001 From: sxyazi Date: Fri, 17 Jan 2025 18:32:55 +0800 Subject: [PATCH] .. --- yazi-ffi/src/cf_dict.rs | 6 ++++-- yazi-fs/src/mounts/macos.rs | 12 ++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/yazi-ffi/src/cf_dict.rs b/yazi-ffi/src/cf_dict.rs index 94a35299..b535e2ed 100644 --- a/yazi-ffi/src/cf_dict.rs +++ b/yazi-ffi/src/cf_dict.rs @@ -11,7 +11,7 @@ pub struct CFDict(CFDictionaryRef); impl CFDict { pub fn take(dict: CFDictionaryRef) -> Result { if dict.is_null() { - bail!("Null pointer"); + bail!("Cannot take a null pointer"); } Ok(Self(dict)) } @@ -19,7 +19,9 @@ impl CFDict { pub fn value(&self, key: &str) -> Result<*const c_void> { let key_ = CFString::new(key)?; let mut value = std::ptr::null(); - if unsafe { CFDictionaryGetValueIfPresent(self.0, key_.as_void_ptr(), &mut value) } == 0 { + if unsafe { CFDictionaryGetValueIfPresent(self.0, key_.as_void_ptr(), &mut value) } == 0 + || value.is_null() + { bail!("Cannot get the value for the key `{key}`"); } Ok(value) diff --git a/yazi-fs/src/mounts/macos.rs b/yazi-fs/src/mounts/macos.rs index 929a0af1..1cd7d96c 100644 --- a/yazi-fs/src/mounts/macos.rs +++ b/yazi-fs/src/mounts/macos.rs @@ -17,6 +17,10 @@ impl Partitions { { tokio::task::spawn_blocking(move || { let session = unsafe { DASessionCreate(kCFAllocatorDefault) }; + if session.is_null() { + return error!("Cannot create a disk arbitration session"); + } + defer! { unsafe { CFRelease(session) } }; extern "C" fn on_appeared(_disk: *const c_void, context: *mut c_void) { let boxed = context as *mut Box; @@ -85,6 +89,10 @@ impl Partitions { fn all_partitions(names: Vec) -> Result> { let session = unsafe { DASessionCreate(kCFAllocatorDefault) }; + if session.is_null() { + bail!("Cannot create a disk arbitration session"); + } + defer! { unsafe { CFRelease(session) } }; let mut disks = Vec::with_capacity(names.len()); for name in names { @@ -93,7 +101,7 @@ impl Partitions { continue; } - defer! { unsafe { CFRelease(disk as _) } }; + defer! { unsafe { CFRelease(disk) } }; let Ok(dict) = CFDict::take(unsafe { DADiskCopyDescription(disk) }) else { continue; }; @@ -120,7 +128,7 @@ impl Partitions { }; if result != 0 { - bail!("IOServiceGetMatchingServices failed"); + bail!("Cannot get the IO matching services"); } defer! { unsafe { IOObjectRelease(iterator); } };