mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-25 05:26:50 +00:00
feat: add FileAccessDeniedWithContext error type for better file access error handling
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
use std::io::{self, ErrorKind};
|
use std::io::{self, ErrorKind};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
@@ -345,6 +346,19 @@ pub fn os_err_to_file_err(e: io::Error) -> Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub struct FileAccessDeniedWithContext {
|
||||||
|
pub path: PathBuf,
|
||||||
|
#[source]
|
||||||
|
pub source: std::io::Error,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for FileAccessDeniedWithContext {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "访问文件 '{}' 被拒绝: {}", self.path.display(), self.source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_unformatted_disk(err: &Error) -> bool {
|
pub fn is_unformatted_disk(err: &Error) -> bool {
|
||||||
matches!(err.downcast_ref::<DiskError>(), Some(DiskError::UnformattedDisk))
|
matches!(err.downcast_ref::<DiskError>(), Some(DiskError::UnformattedDisk))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use crate::bucket::metadata_sys::{self};
|
|||||||
use crate::cache_value::cache::{Cache, Opts, UpdateFn};
|
use crate::cache_value::cache::{Cache, Opts, UpdateFn};
|
||||||
use crate::disk::error::{
|
use crate::disk::error::{
|
||||||
convert_access_error, is_err_os_not_exist, is_sys_err_handle_invalid, is_sys_err_invalid_arg, is_sys_err_is_dir,
|
convert_access_error, is_err_os_not_exist, is_sys_err_handle_invalid, is_sys_err_invalid_arg, is_sys_err_is_dir,
|
||||||
is_sys_err_not_dir, map_err_not_exists, os_err_to_file_err,
|
is_sys_err_not_dir, map_err_not_exists, os_err_to_file_err, FileAccessDeniedWithContext
|
||||||
};
|
};
|
||||||
use crate::disk::os::{check_path_length, is_empty_dir};
|
use crate::disk::os::{check_path_length, is_empty_dir};
|
||||||
use crate::disk::STORAGE_FORMAT_FILE;
|
use crate::disk::STORAGE_FORMAT_FILE;
|
||||||
|
|||||||
Reference in New Issue
Block a user