mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-07 13:53:12 +00:00
update stock api
This commit is contained in:
@@ -205,7 +205,7 @@ pub fn clone_disk_err(e: &DiskError) -> Error {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ioerr_to_err(e: io::Error) -> Error {
|
||||
pub fn os_err_to_file_err(e: io::Error) -> Error {
|
||||
match e.kind() {
|
||||
io::ErrorKind::NotFound => Error::new(DiskError::FileNotFound),
|
||||
io::ErrorKind::PermissionDenied => Error::new(DiskError::FileAccessDenied),
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::{
|
||||
os, DeleteOptions, DiskAPI, DiskLocation, FileInfoVersions, FileReader, FileWriter, MetaCacheEntry, ReadMultipleReq,
|
||||
ReadMultipleResp, ReadOptions, RenameDataResp, UpdateMetadataOpts, VolumeInfo, WalkDirOptions,
|
||||
};
|
||||
use crate::disk::error::{is_sys_err_not_dir, map_err_not_exists};
|
||||
use crate::disk::error::{is_sys_err_not_dir, map_err_not_exists, os_err_to_file_err};
|
||||
use crate::disk::os::check_path_length;
|
||||
use crate::disk::{LocalFileReader, LocalFileWriter, STORAGE_FORMAT_FILE};
|
||||
use crate::utils::fs::lstat;
|
||||
@@ -25,7 +25,6 @@ use time::OffsetDateTime;
|
||||
use tokio::fs::{self, File};
|
||||
use tokio::io::ErrorKind;
|
||||
use tokio::sync::Mutex;
|
||||
use tower::layer::util;
|
||||
use tracing::{debug, warn};
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -679,7 +678,31 @@ impl DiskAPI for LocalDisk {
|
||||
}
|
||||
}
|
||||
|
||||
unimplemented!()
|
||||
if let Err(err) = os::rename_all(&src_file_path, &dst_file_path, &dst_volume_dir).await {
|
||||
if let Some(e) = err.to_io_err() {
|
||||
if is_sys_err_not_empty(&e) || is_sys_err_not_dir(&e) {
|
||||
return Err(Error::new(DiskError::FileAccessDenied));
|
||||
}
|
||||
|
||||
return Err(os_err_to_file_err(e));
|
||||
}
|
||||
|
||||
return Err(err);
|
||||
}
|
||||
|
||||
if let Err(err) = self.write_all(&dst_volume, format!("{}.meta", dst_path).as_str(), meta).await {
|
||||
if let Some(e) = err.to_io_err() {
|
||||
return Err(os_err_to_file_err(e));
|
||||
}
|
||||
|
||||
return Err(err);
|
||||
}
|
||||
|
||||
if let Some(parent) = src_file_path.parent() {
|
||||
self.delete_file(&src_volume_dir, &parent.to_path_buf(), false, false).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
async fn rename_file(&self, src_volume: &str, src_path: &str, dst_volume: &str, dst_path: &str) -> Result<()> {
|
||||
let src_volume_path = self.get_bucket_path(src_volume)?;
|
||||
@@ -1009,8 +1032,8 @@ impl DiskAPI for LocalDisk {
|
||||
|
||||
let p = self.get_bucket_path(volume)?;
|
||||
|
||||
if let Err(err) = utils::fs::access(&p).await {
|
||||
if os_is_not_exist(err) {
|
||||
if let Err(e) = utils::fs::access(&p).await {
|
||||
if os_is_not_exist(&e) {
|
||||
os::make_dir_all(&p).await?;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-4
@@ -12,7 +12,7 @@ use crate::{
|
||||
utils,
|
||||
};
|
||||
|
||||
use super::error::{ioerr_to_err, os_is_exist, DiskError};
|
||||
use super::error::{os_err_to_file_err, os_is_exist, DiskError};
|
||||
|
||||
pub fn check_path_length(path_name: &str) -> Result<()> {
|
||||
// Apple OS X path length is limited to 1016
|
||||
@@ -55,7 +55,7 @@ pub fn check_path_length(path_name: &str) -> Result<()> {
|
||||
pub async fn make_dir_all(path: impl AsRef<Path>) -> Result<()> {
|
||||
check_path_length(path.as_ref().to_string_lossy().to_string().as_str())?;
|
||||
|
||||
utils::fs::make_dir_all(path.as_ref()).map_err(ioerr_to_err).await?;
|
||||
utils::fs::make_dir_all(path.as_ref()).map_err(os_err_to_file_err).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -147,7 +147,7 @@ pub async fn reliable_rename(
|
||||
pub async fn reliable_mkdir_all(path: impl AsRef<Path>, base_dir: impl AsRef<Path>) -> io::Result<()> {
|
||||
let mut i = 0;
|
||||
|
||||
let mut base_dir = base_dir.as_ref().clone();
|
||||
let mut base_dir = base_dir.as_ref();
|
||||
loop {
|
||||
if let Err(e) = os_mkdir_all(path.as_ref(), base_dir).await {
|
||||
if os_is_not_exist(&e) && i == 0 {
|
||||
@@ -180,7 +180,15 @@ pub async fn os_mkdir_all(dir_path: impl AsRef<Path>, base_dir: impl AsRef<Path>
|
||||
}
|
||||
|
||||
if let Some(parent) = dir_path.as_ref().parent() {
|
||||
Box::pin(os_mkdir_all(parent, base_dir)).await?;
|
||||
// 不支持递归,直接create_dir_all了
|
||||
if let Err(e) = fs::create_dir_all(&parent).await {
|
||||
if os_is_exist(&e) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
return Err(e);
|
||||
}
|
||||
// Box::pin(os_mkdir_all(&parent, &base_dir)).await?;
|
||||
}
|
||||
|
||||
if let Err(e) = utils::fs::mkdir(dir_path.as_ref()).await {
|
||||
|
||||
@@ -65,6 +65,14 @@ impl Error {
|
||||
pub fn downcast_mut<T: std::error::Error + 'static>(&mut self) -> Option<&mut T> {
|
||||
self.inner.downcast_mut()
|
||||
}
|
||||
|
||||
pub fn to_io_err(&self) -> Option<io::Error> {
|
||||
if let Some(e) = self.downcast_ref::<io::Error>() {
|
||||
Some(io::Error::new(e.kind(), e.to_string()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: std::error::Error + Send + Sync + 'static> From<T> for Error {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::path::Path;
|
||||
|
||||
const GLOBAL_DIR_SUFFIX: &str = "__XLDIR__";
|
||||
|
||||
pub const SLASH_SEPARATOR: &str = "/";
|
||||
@@ -39,7 +37,3 @@ pub fn retain_slash(s: &str) -> String {
|
||||
format!("{}{}", s, SLASH_SEPARATOR)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn join(p1: &str, p2: &str) -> String {
|
||||
Path::new(p1).join(Path::new(p2)).to_string_lossy().to_string()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user