Because of the function get_system_volumes_information() program can not see two disk with the different mount but with the same name (in my case the name is vide). I fix it by this code:
`pub fn get_system_volumes_information() -> Vec {
let mut volume_information_vec: Vec = Vec::new();
let disks = Disks::new_with_refreshed_list();
for disk in &disks {
volume_information_vec.push(VolumeInformation {
volume_name: disk.name().to_string_lossy().into_owned(), // Convert OsStr to String
mount_point: disk.mount_point().to_string_lossy().into_owned(), // Convert mount point
file_system: disk
.file_system()
.to_str()
.expect("Error during parsing the given string from file_system")
.to_owned(), // Convert file system
size: disk.total_space(),
available_space: disk.available_space(),
is_removable: disk.is_removable(),
total_written_bytes: disk.usage().total_written_bytes,
total_read_bytes: disk.usage().total_read_bytes,
});
}
for disk in &disks {
println!(
"DISK: mount={:?}, name={:?}, fs={:?}, size={}, free={}",
disk.mount_point(),
disk.name(),
disk.file_system(),
disk.total_space(),
disk.available_space()
);
}
// Create a new vector to store non-duplicate items
let mut result = Vec::new();
let mut skip_indices = std::collections::HashSet::new();
// First pass: identify duplicates
for i in 0..volume_information_vec.len() {
if skip_indices.contains(&i) {
continue;
}
for j in i + 1..volume_information_vec.len() {
// The mount point uniquely identifies the logical drive.
if volume_information_vec[i].mount_point
== volume_information_vec[j].mount_point
{
// Keep the entry with the more useful volume name.
if volume_information_vec[i].volume_name.len()
> volume_information_vec[j].volume_name.len()
{
skip_indices.insert(j);
} else {
skip_indices.insert(i);
}
}
}
}
Because of the function get_system_volumes_information() program can not see two disk with the different mount but with the same name (in my case the name is vide). I fix it by this code:
`pub fn get_system_volumes_information() -> Vec {
let mut volume_information_vec: Vec = Vec::new();
let disks = Disks::new_with_refreshed_list();
....`