feat: add FileAccessDeniedWithContext error type for better file access error handling

This commit is contained in:
Damonxue
2025-04-09 10:25:41 +08:00
parent b2f5e28b95
commit 71d6d9ec48
2 changed files with 15 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
use std::io::{self, ErrorKind};
use std::path::PathBuf;
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 {
matches!(err.downcast_ref::<DiskError>(), Some(DiskError::UnformattedDisk))
}

View File

@@ -14,7 +14,7 @@ use crate::bucket::metadata_sys::{self};
use crate::cache_value::cache::{Cache, Opts, UpdateFn};
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,
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::STORAGE_FORMAT_FILE;