Skip to content

Commit

Permalink
Improve ejectable disk detection on Apple platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
complexspaces committed Oct 5, 2022
1 parent 2fc5e41 commit 31fedc6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/apple/disk.rs
Expand Up @@ -101,6 +101,7 @@ pub(super) fn get_disks() -> Vec<Disk> {
build_requested_properties(&[
ffi::kCFURLVolumeIsEjectableKey,
ffi::kCFURLVolumeIsRemovableKey,
ffi::kCFURLVolumeIsInternalKey,
ffi::kCFURLVolumeTotalCapacityKey,
ffi::kCFURLVolumeAvailableCapacityForImportantUsageKey,
ffi::kCFURLVolumeAvailableCapacityKey,
Expand Down Expand Up @@ -342,7 +343,21 @@ fn new_disk(
)
.unwrap();

ejectable || removable
let is_removable = ejectable || removable;

if is_removable {
is_removable
} else {
// If neither `ejectable` or `removable` return `true`, fallback to checking
// if the disk is attached to the internal system.
let internal = get_bool_value(
disk_props.inner(),
DictKey::Extern(ffi::kCFURLVolumeIsInternalKey),
)
.unwrap();

!internal
}
};

let total_space = unsafe {
Expand Down
1 change: 1 addition & 0 deletions src/apple/ffi.rs
Expand Up @@ -23,6 +23,7 @@ extern "C" {
pub static kCFURLVolumeTotalCapacityKey: CFStringRef;
pub static kCFURLVolumeNameKey: CFStringRef;
pub static kCFURLVolumeIsLocalKey: CFStringRef;
pub static kCFURLVolumeIsInternalKey: CFStringRef;
pub static kCFURLVolumeIsBrowsableKey: CFStringRef;
}

Expand Down

0 comments on commit 31fedc6

Please sign in to comment.