mirror of
https://github.com/bootandy/dust.git
synced 2025-12-12 07:40:40 -08:00
get_filesystem returns Result instead of option
Removes unwrap and returns a Result instead of panicing if an invalid path is given. Previously if the flag: '-x' was provided with an argument of an invalid directory the code would crash here
This commit is contained in:
@@ -100,7 +100,7 @@ pub fn get_dir_tree(
|
||||
fn get_allowed_filesystems(top_level_names: &HashSet<String>) -> Option<HashSet<u64>> {
|
||||
let mut limit_filesystems: HashSet<u64> = HashSet::new();
|
||||
for file_name in top_level_names.iter() {
|
||||
if let Some(a) = get_filesystem(file_name) {
|
||||
if let Ok(a) = get_filesystem(file_name) {
|
||||
limit_filesystems.insert(a);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use jwalk::DirEntry;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
fn get_block_size() -> u64 {
|
||||
@@ -41,20 +42,20 @@ pub fn get_metadata(d: &DirEntry, _apparent: bool) -> Option<(u64, Option<(u64,
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn get_filesystem(file_path: &str) -> Option<u64> {
|
||||
pub fn get_filesystem(file_path: &str) -> Result<u64, io::Error> {
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
let metadata = fs::metadata(file_path).unwrap();
|
||||
Some(metadata.dev())
|
||||
let metadata = fs::metadata(file_path)?;
|
||||
Ok(metadata.dev())
|
||||
}
|
||||
|
||||
#[cfg(target_family = "windows")]
|
||||
pub fn get_device(file_path: &str) -> Option<u64> {
|
||||
pub fn get_device(file_path: &str) -> Result<u64, io::Error> {
|
||||
use std::os::windows::fs::MetadataExt;
|
||||
let metadata = fs::metadata(file_path).unwrap();
|
||||
Some(metadata.volume_serial_number())
|
||||
let metadata = fs::metadata(file_path)?;
|
||||
Ok(metadata.volume_serial_number())
|
||||
}
|
||||
|
||||
#[cfg(all(not(target_family = "windows"), not(target_family = "unix")))]
|
||||
pub fn get_device(file_path: &str) -> Option<u64> {
|
||||
pub fn get_device(file_path: &str) -> Result<u64, io::Error> {
|
||||
None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user