mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-27 00:38:16 +00:00
fix: 优化unused
This commit is contained in:
+68
-62
@@ -1,17 +1,15 @@
|
||||
use std::{
|
||||
fs::Metadata,
|
||||
path::{Path, PathBuf},
|
||||
sync::{Arc, RwLock},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use anyhow::{Error, Result};
|
||||
use bytes::Bytes;
|
||||
use futures::{future::join_all, Stream};
|
||||
use futures::future::join_all;
|
||||
use path_absolutize::Absolutize;
|
||||
use s3s::StdError;
|
||||
use time::OffsetDateTime;
|
||||
use tokio::io::{self, AsyncRead, AsyncReadExt, AsyncSeekExt};
|
||||
use tokio::io::{AsyncWrite, BufWriter, ErrorKind};
|
||||
use tokio::io::{self, BufWriter, ErrorKind};
|
||||
use tokio::{
|
||||
fs::{self, File},
|
||||
io::DuplexStream,
|
||||
@@ -23,7 +21,7 @@ use crate::{
|
||||
disk_api::{DiskAPI, DiskError, ReadOptions, VolumeInfo},
|
||||
endpoint::{Endpoint, Endpoints},
|
||||
file_meta::FileMeta,
|
||||
format::{DistributionAlgoVersion, FormatV3},
|
||||
format::FormatV3,
|
||||
store_api::{FileInfo, RawFileInfo},
|
||||
utils,
|
||||
};
|
||||
@@ -48,6 +46,7 @@ pub async fn new_disk(ep: &Endpoint, opt: &DiskOption) -> Result<DiskStore> {
|
||||
let s = LocalDisk::new(ep, opt.cleanup).await?;
|
||||
Ok(Arc::new(Box::new(s)))
|
||||
} else {
|
||||
let _ = opt.health_check;
|
||||
unimplemented!()
|
||||
// Ok(Disk::Remote(RemoteDisk::new(ep, opt.health_check)?))
|
||||
}
|
||||
@@ -168,22 +167,22 @@ impl LocalDisk {
|
||||
self.resolve_abs_path(dir)
|
||||
}
|
||||
|
||||
/// Write to the filesystem atomically.
|
||||
/// This is done by first writing to a temporary location and then moving the file.
|
||||
pub(crate) async fn prepare_file_write<'a>(&self, path: &'a PathBuf) -> Result<FileWriter<'a>> {
|
||||
let tmp_path = self.get_object_path(RUSTFS_META_TMP_BUCKET, Uuid::new_v4().to_string().as_str())?;
|
||||
// /// Write to the filesystem atomically.
|
||||
// /// This is done by first writing to a temporary location and then moving the file.
|
||||
// pub(crate) async fn prepare_file_write<'a>(&self, path: &'a PathBuf) -> Result<FileWriter<'a>> {
|
||||
// let tmp_path = self.get_object_path(RUSTFS_META_TMP_BUCKET, Uuid::new_v4().to_string().as_str())?;
|
||||
|
||||
debug!("prepare_file_write tmp_path:{:?}, path:{:?}", &tmp_path, &path);
|
||||
// debug!("prepare_file_write tmp_path:{:?}, path:{:?}", &tmp_path, &path);
|
||||
|
||||
let file = File::create(&tmp_path).await?;
|
||||
let writer = BufWriter::new(file);
|
||||
Ok(FileWriter {
|
||||
tmp_path,
|
||||
dest_path: path,
|
||||
writer,
|
||||
clean_tmp: true,
|
||||
})
|
||||
}
|
||||
// let file = File::create(&tmp_path).await?;
|
||||
// let writer = BufWriter::new(file);
|
||||
// Ok(FileWriter {
|
||||
// tmp_path,
|
||||
// dest_path: path,
|
||||
// writer,
|
||||
// clean_tmp: true,
|
||||
// })
|
||||
// }
|
||||
|
||||
pub async fn rename_all(&self, src_data_path: &PathBuf, dst_data_path: &PathBuf, skip: &PathBuf) -> Result<()> {
|
||||
if !skip.starts_with(&src_data_path) {
|
||||
@@ -247,8 +246,8 @@ impl LocalDisk {
|
||||
|
||||
async fn read_all_data(
|
||||
&self,
|
||||
bucket: &str,
|
||||
volume_dir: impl AsRef<Path>,
|
||||
_bucket: &str,
|
||||
_volume_dir: impl AsRef<Path>,
|
||||
path: impl AsRef<Path>,
|
||||
) -> Result<(Vec<u8>, OffsetDateTime)> {
|
||||
let (data, meta) = read_file_all(path).await?;
|
||||
@@ -404,7 +403,14 @@ impl DiskAPI for LocalDisk {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn create_file(&self, origvolume: &str, volume: &str, path: &str, fileSize: usize, mut r: DuplexStream) -> Result<()> {
|
||||
async fn create_file(
|
||||
&self,
|
||||
_origvolume: &str,
|
||||
volume: &str,
|
||||
path: &str,
|
||||
_file_size: usize,
|
||||
mut r: DuplexStream,
|
||||
) -> Result<()> {
|
||||
let fpath = self.get_object_path(volume, path)?;
|
||||
|
||||
debug!("CreateFile fpath: {:?}", fpath);
|
||||
@@ -461,15 +467,15 @@ impl DiskAPI for LocalDisk {
|
||||
|
||||
let (dst_buf, _) = read_file_exists(&dst_file_path).await?;
|
||||
|
||||
let mut skipParent = dst_volume_path;
|
||||
let mut skip_parent = dst_volume_path;
|
||||
if !&dst_buf.is_empty() {
|
||||
skipParent = PathBuf::from(&dst_file_path.parent().unwrap_or(Path::new("/")));
|
||||
skip_parent = PathBuf::from(&dst_file_path.parent().unwrap_or(Path::new("/")));
|
||||
}
|
||||
|
||||
if !dst_buf.is_empty() {
|
||||
meta = match FileMeta::unmarshal(&dst_buf) {
|
||||
Ok(m) => m,
|
||||
Err(e) => FileMeta::new(),
|
||||
Err(_) => FileMeta::new(),
|
||||
}
|
||||
// xl.load
|
||||
// meta.from(dst_buf);
|
||||
@@ -483,10 +489,10 @@ impl DiskAPI for LocalDisk {
|
||||
|
||||
let no_inline = src_data_path.has_root() && fi.data.is_none() && fi.size > 0;
|
||||
if no_inline {
|
||||
self.rename_all(&src_data_path, &dst_data_path, &skipParent).await?;
|
||||
self.rename_all(&src_data_path, &dst_data_path, &skip_parent).await?;
|
||||
}
|
||||
|
||||
self.rename_all(&src_file_path, &dst_file_path, &skipParent).await?;
|
||||
self.rename_all(&src_file_path, &dst_file_path, &skip_parent).await?;
|
||||
|
||||
if src_volume != RUSTFS_META_MULTIPART_BUCKET {
|
||||
fs::remove_dir(&src_file_path.parent().unwrap()).await?;
|
||||
@@ -542,7 +548,7 @@ impl DiskAPI for LocalDisk {
|
||||
})
|
||||
}
|
||||
|
||||
async fn write_metadata(&self, org_volume: &str, volume: &str, path: &str, fi: FileInfo) -> Result<()> {
|
||||
async fn write_metadata(&self, _org_volume: &str, volume: &str, path: &str, fi: FileInfo) -> Result<()> {
|
||||
let p = self.get_object_path(&volume, format!("{}/{}", path, STORAGE_FORMAT_FILE).as_str())?;
|
||||
|
||||
let mut meta = FileMeta::new();
|
||||
@@ -564,7 +570,7 @@ impl DiskAPI for LocalDisk {
|
||||
|
||||
async fn read_version(
|
||||
&self,
|
||||
org_volume: &str,
|
||||
_org_volume: &str,
|
||||
volume: &str,
|
||||
path: &str,
|
||||
version_id: Uuid,
|
||||
@@ -618,44 +624,44 @@ impl DiskAPI for LocalDisk {
|
||||
// }
|
||||
// }
|
||||
|
||||
pub(crate) struct FileWriter<'a> {
|
||||
tmp_path: PathBuf,
|
||||
dest_path: &'a Path,
|
||||
writer: BufWriter<File>,
|
||||
clean_tmp: bool,
|
||||
}
|
||||
// pub(crate) struct FileWriter<'a> {
|
||||
// tmp_path: PathBuf,
|
||||
// dest_path: &'a Path,
|
||||
// writer: BufWriter<File>,
|
||||
// clean_tmp: bool,
|
||||
// }
|
||||
|
||||
impl<'a> FileWriter<'a> {
|
||||
pub(crate) fn tmp_path(&self) -> &Path {
|
||||
&self.tmp_path
|
||||
}
|
||||
// impl<'a> FileWriter<'a> {
|
||||
// pub(crate) fn tmp_path(&self) -> &Path {
|
||||
// &self.tmp_path
|
||||
// }
|
||||
|
||||
pub(crate) fn dest_path(&self) -> &'a Path {
|
||||
self.dest_path
|
||||
}
|
||||
// pub(crate) fn dest_path(&self) -> &'a Path {
|
||||
// self.dest_path
|
||||
// }
|
||||
|
||||
pub(crate) fn writer(&mut self) -> &mut BufWriter<File> {
|
||||
&mut self.writer
|
||||
}
|
||||
// pub(crate) fn writer(&mut self) -> &mut BufWriter<File> {
|
||||
// &mut self.writer
|
||||
// }
|
||||
|
||||
pub(crate) async fn done(mut self) -> Result<()> {
|
||||
if let Some(final_dir_path) = self.dest_path().parent() {
|
||||
fs::create_dir_all(&final_dir_path).await?;
|
||||
}
|
||||
// pub(crate) async fn done(mut self) -> Result<()> {
|
||||
// if let Some(final_dir_path) = self.dest_path().parent() {
|
||||
// fs::create_dir_all(&final_dir_path).await?;
|
||||
// }
|
||||
|
||||
fs::rename(&self.tmp_path, self.dest_path()).await?;
|
||||
self.clean_tmp = false;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
// fs::rename(&self.tmp_path, self.dest_path()).await?;
|
||||
// self.clean_tmp = false;
|
||||
// Ok(())
|
||||
// }
|
||||
// }
|
||||
|
||||
impl<'a> Drop for FileWriter<'a> {
|
||||
fn drop(&mut self) {
|
||||
if self.clean_tmp {
|
||||
let _ = std::fs::remove_file(&self.tmp_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
// impl<'a> Drop for FileWriter<'a> {
|
||||
// fn drop(&mut self) {
|
||||
// if self.clean_tmp {
|
||||
// let _ = std::fs::remove_file(&self.tmp_path);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
@@ -15,7 +15,7 @@ pub trait DiskAPI: Debug + Send + Sync + 'static {
|
||||
async fn read_all(&self, volume: &str, path: &str) -> Result<Bytes>;
|
||||
async fn write_all(&self, volume: &str, path: &str, data: Bytes) -> Result<()>;
|
||||
async fn rename_file(&self, src_volume: &str, src_path: &str, dst_volume: &str, dst_path: &str) -> Result<()>;
|
||||
async fn create_file(&self, origvolume: &str, volume: &str, path: &str, fileSize: usize, r: DuplexStream) -> Result<()>;
|
||||
async fn create_file(&self, origvolume: &str, volume: &str, path: &str, file_size: usize, r: DuplexStream) -> Result<()>;
|
||||
async fn rename_data(
|
||||
&self,
|
||||
src_volume: &str,
|
||||
|
||||
+14
-14
@@ -1,5 +1,5 @@
|
||||
use anyhow::anyhow;
|
||||
use anyhow::{Error, Result};
|
||||
use anyhow::Result;
|
||||
use bytes::Bytes;
|
||||
use futures::{Stream, StreamExt};
|
||||
use reed_solomon_erasure::galois_8::ReedSolomon;
|
||||
@@ -11,16 +11,16 @@ use tracing::debug;
|
||||
use crate::chunk_stream::ChunkedStream;
|
||||
|
||||
pub struct Erasure {
|
||||
data_shards: usize,
|
||||
parity_shards: usize,
|
||||
// data_shards: usize,
|
||||
// parity_shards: usize,
|
||||
encoder: ReedSolomon,
|
||||
}
|
||||
|
||||
impl Erasure {
|
||||
pub fn new(data_shards: usize, parity_shards: usize) -> Self {
|
||||
Erasure {
|
||||
data_shards,
|
||||
parity_shards,
|
||||
// data_shards,
|
||||
// parity_shards,
|
||||
encoder: ReedSolomon::new(data_shards, parity_shards).unwrap(),
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ impl Erasure {
|
||||
writers: &mut Vec<W>,
|
||||
block_size: usize,
|
||||
data_size: usize,
|
||||
write_quorum: usize,
|
||||
_write_quorum: usize,
|
||||
) -> Result<usize>
|
||||
where
|
||||
S: Stream<Item = Result<Bytes, StdError>> + Send + Sync + 'static,
|
||||
@@ -116,15 +116,15 @@ impl Erasure {
|
||||
}
|
||||
}
|
||||
|
||||
fn shards_to_option_shards<T: Clone>(shards: &[Vec<T>]) -> Vec<Option<Vec<T>>> {
|
||||
let mut result = Vec::with_capacity(shards.len());
|
||||
// fn shards_to_option_shards<T: Clone>(shards: &[Vec<T>]) -> Vec<Option<Vec<T>>> {
|
||||
// let mut result = Vec::with_capacity(shards.len());
|
||||
|
||||
for v in shards.iter() {
|
||||
let inner: Vec<T> = v.clone();
|
||||
result.push(Some(inner));
|
||||
}
|
||||
result
|
||||
}
|
||||
// for v in shards.iter() {
|
||||
// let inner: Vec<T> = v.clone();
|
||||
// result.push(Some(inner));
|
||||
// }
|
||||
// result
|
||||
// }
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
@@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
|
||||
use serde_json::Error as JsonError;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{disk, disk_api::DiskError};
|
||||
use crate::disk_api::DiskError;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||
pub enum FormatMetaVersion {
|
||||
|
||||
+10
-10
@@ -2,7 +2,6 @@ use anyhow::{Error, Result};
|
||||
use async_trait::async_trait;
|
||||
use futures::future::join_all;
|
||||
use std::{fmt::Debug, sync::Arc};
|
||||
use tracing::debug;
|
||||
|
||||
use crate::{
|
||||
disk::DiskStore,
|
||||
@@ -141,15 +140,15 @@ impl PeerS3Client for S3PeerSys {
|
||||
#[derive(Debug)]
|
||||
pub struct LocalPeerS3Client {
|
||||
pub local_disks: Vec<DiskStore>,
|
||||
pub node: Node,
|
||||
// pub node: Node,
|
||||
pub pools: Vec<usize>,
|
||||
}
|
||||
|
||||
impl LocalPeerS3Client {
|
||||
fn new(local_disks: Vec<DiskStore>, node: Node, pools: Vec<usize>) -> Self {
|
||||
fn new(local_disks: Vec<DiskStore>, _node: Node, pools: Vec<usize>) -> Self {
|
||||
Self {
|
||||
local_disks,
|
||||
node,
|
||||
// node,
|
||||
pools,
|
||||
}
|
||||
}
|
||||
@@ -192,7 +191,7 @@ impl PeerS3Client for LocalPeerS3Client {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
async fn get_bucket_info(&self, bucket: &str, opts: &BucketOptions) -> Result<BucketInfo> {
|
||||
async fn get_bucket_info(&self, bucket: &str, _opts: &BucketOptions) -> Result<BucketInfo> {
|
||||
let mut futures = Vec::with_capacity(self.local_disks.len());
|
||||
for disk in self.local_disks.iter() {
|
||||
futures.push(disk.stat_volume(bucket));
|
||||
@@ -233,13 +232,14 @@ impl PeerS3Client for LocalPeerS3Client {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RemotePeerS3Client {
|
||||
pub node: Node,
|
||||
pub pools: Vec<usize>,
|
||||
// pub node: Node,
|
||||
// pub pools: Vec<usize>,
|
||||
}
|
||||
|
||||
impl RemotePeerS3Client {
|
||||
fn new(node: Node, pools: Vec<usize>) -> Self {
|
||||
Self { node, pools }
|
||||
fn new(_node: Node, _pools: Vec<usize>) -> Self {
|
||||
// Self { node, pools }
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ impl PeerS3Client for RemotePeerS3Client {
|
||||
async fn make_bucket(&self, _bucket: &str, _opts: &MakeBucketOptions) -> Result<()> {
|
||||
unimplemented!()
|
||||
}
|
||||
async fn get_bucket_info(&self, bucket: &str, opts: &BucketOptions) -> Result<BucketInfo> {
|
||||
async fn get_bucket_info(&self, _bucket: &str, _opts: &BucketOptions) -> Result<BucketInfo> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
+20
-30
@@ -1,13 +1,11 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{Error, Result};
|
||||
use futures::{future::join_all, AsyncWrite, StreamExt};
|
||||
use futures::future::join_all;
|
||||
use time::OffsetDateTime;
|
||||
use tracing::debug;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
disk::{self, DiskStore, RUSTFS_META_MULTIPART_BUCKET, RUSTFS_META_TMP_BUCKET},
|
||||
disk::{DiskStore, RUSTFS_META_MULTIPART_BUCKET, RUSTFS_META_TMP_BUCKET},
|
||||
endpoint::PoolEndpoints,
|
||||
erasure::Erasure,
|
||||
format::{DistributionAlgoVersion, FormatV3},
|
||||
@@ -21,8 +19,6 @@ use crate::{
|
||||
},
|
||||
};
|
||||
|
||||
const DEFAULT_INLINE_BLOCKS: usize = 128 * 1024;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Sets {
|
||||
pub id: Uuid,
|
||||
@@ -135,16 +131,16 @@ impl Sets {
|
||||
errors
|
||||
}
|
||||
|
||||
async fn commit_rename_data_dir(
|
||||
&self,
|
||||
disks: &Vec<Option<DiskStore>>,
|
||||
bucket: &str,
|
||||
object: &str,
|
||||
data_dir: &str,
|
||||
// write_quorum: usize,
|
||||
) -> Vec<Option<Error>> {
|
||||
unimplemented!()
|
||||
}
|
||||
// async fn commit_rename_data_dir(
|
||||
// &self,
|
||||
// disks: &Vec<Option<DiskStore>>,
|
||||
// bucket: &str,
|
||||
// object: &str,
|
||||
// data_dir: &str,
|
||||
// // write_quorum: usize,
|
||||
// ) -> Vec<Option<Error>> {
|
||||
// unimplemented!()
|
||||
// }
|
||||
}
|
||||
|
||||
async fn write_unique_file_info(
|
||||
@@ -202,14 +198,6 @@ fn get_multipart_sha_dir(bucket: &str, object: &str) -> String {
|
||||
hex(sha256(path.as_bytes()).as_ref())
|
||||
}
|
||||
|
||||
async fn check_upload_idexists() -> Result<()> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
async fn read_all_file_info() -> Result<()> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
// #[derive(Debug)]
|
||||
// pub struct Objects {
|
||||
// pub endpoints: Vec<Endpoint>,
|
||||
@@ -222,11 +210,11 @@ async fn read_all_file_info() -> Result<()> {
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl StorageAPI for Sets {
|
||||
async fn make_bucket(&self, bucket: &str, opts: &MakeBucketOptions) -> Result<()> {
|
||||
async fn make_bucket(&self, _bucket: &str, _opts: &MakeBucketOptions) -> Result<()> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
async fn get_bucket_info(&self, bucket: &str, opts: &BucketOptions) -> Result<BucketInfo> {
|
||||
async fn get_bucket_info(&self, _bucket: &str, _opts: &BucketOptions) -> Result<BucketInfo> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
@@ -339,11 +327,11 @@ impl StorageAPI for Sets {
|
||||
bucket: &str,
|
||||
object: &str,
|
||||
upload_id: &str,
|
||||
part_id: usize,
|
||||
data: PutObjReader,
|
||||
opts: &ObjectOptions,
|
||||
_part_id: usize,
|
||||
_data: PutObjReader,
|
||||
_opts: &ObjectOptions,
|
||||
) -> Result<PartInfo> {
|
||||
let upload_path = get_upload_id_dir(bucket, object, upload_id);
|
||||
let _upload_path = get_upload_id_dir(bucket, object, upload_id);
|
||||
|
||||
// TODO: checkUploadIDExists
|
||||
|
||||
@@ -364,6 +352,8 @@ impl StorageAPI for Sets {
|
||||
write_quorum += 1
|
||||
}
|
||||
|
||||
let _ = write_quorum;
|
||||
|
||||
let mut fi = FileInfo::new([bucket, object].join("/").as_str(), data_drives, parity_drives);
|
||||
|
||||
fi.data_dir = Uuid::new_v4();
|
||||
|
||||
@@ -3,7 +3,6 @@ use std::collections::HashMap;
|
||||
use anyhow::{Error, Result};
|
||||
|
||||
use s3s::{dto::StreamingBlob, Body};
|
||||
use tracing::debug;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
use std::{default, sync::Arc};
|
||||
|
||||
use anyhow::Result;
|
||||
use bytes::Bytes;
|
||||
use futures::Stream;
|
||||
use s3s::{dto::StreamingBlob, Body};
|
||||
use s3s::dto::StreamingBlob;
|
||||
use time::OffsetDateTime;
|
||||
use tracing::debug;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub const ERASURE_ALGORITHM: &str = "rs-vandermonde";
|
||||
|
||||
+115
-115
@@ -1,133 +1,133 @@
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
// use std::collections::HashMap;
|
||||
// use std::fmt;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct StringSet(HashMap<String, ()>);
|
||||
// #[derive(Debug, Clone)]
|
||||
// pub struct StringSet(HashMap<String, ()>);
|
||||
|
||||
impl StringSet {
|
||||
// ToSlice - returns StringSet as a vector of strings.
|
||||
pub fn to_slice(&self) -> Vec<String> {
|
||||
let mut keys = self.0.keys().cloned().collect::<Vec<String>>();
|
||||
keys.sort();
|
||||
keys
|
||||
}
|
||||
// impl StringSet {
|
||||
// // ToSlice - returns StringSet as a vector of strings.
|
||||
// pub fn to_slice(&self) -> Vec<String> {
|
||||
// let mut keys = self.0.keys().cloned().collect::<Vec<String>>();
|
||||
// keys.sort();
|
||||
// keys
|
||||
// }
|
||||
|
||||
// IsEmpty - returns whether the set is empty or not.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.len() == 0
|
||||
}
|
||||
// // IsEmpty - returns whether the set is empty or not.
|
||||
// pub fn is_empty(&self) -> bool {
|
||||
// self.0.len() == 0
|
||||
// }
|
||||
|
||||
// Add - adds a string to the set.
|
||||
pub fn add(&mut self, s: String) {
|
||||
self.0.insert(s, ());
|
||||
}
|
||||
// // Add - adds a string to the set.
|
||||
// pub fn add(&mut self, s: String) {
|
||||
// self.0.insert(s, ());
|
||||
// }
|
||||
|
||||
// Remove - removes a string from the set. It does nothing if the string does not exist in the set.
|
||||
pub fn remove(&mut self, s: &str) {
|
||||
self.0.remove(s);
|
||||
}
|
||||
// // Remove - removes a string from the set. It does nothing if the string does not exist in the set.
|
||||
// pub fn remove(&mut self, s: &str) {
|
||||
// self.0.remove(s);
|
||||
// }
|
||||
|
||||
// Contains - checks if a string is in the set.
|
||||
pub fn contains(&self, s: &str) -> bool {
|
||||
self.0.contains_key(s)
|
||||
}
|
||||
// // Contains - checks if a string is in the set.
|
||||
// pub fn contains(&self, s: &str) -> bool {
|
||||
// self.0.contains_key(s)
|
||||
// }
|
||||
|
||||
// FuncMatch - returns a new set containing each value that passes the match function.
|
||||
pub fn func_match<F>(&self, match_fn: F, match_string: &str) -> StringSet
|
||||
where
|
||||
F: Fn(&str, &str) -> bool,
|
||||
{
|
||||
StringSet(
|
||||
self.0
|
||||
.iter()
|
||||
.filter(|(k, _)| match_fn(k, match_string))
|
||||
.map(|(k, _)| (k.clone(), ()))
|
||||
.collect::<HashMap<String, ()>>(),
|
||||
)
|
||||
}
|
||||
// // FuncMatch - returns a new set containing each value that passes the match function.
|
||||
// pub fn func_match<F>(&self, match_fn: F, match_string: &str) -> StringSet
|
||||
// where
|
||||
// F: Fn(&str, &str) -> bool,
|
||||
// {
|
||||
// StringSet(
|
||||
// self.0
|
||||
// .iter()
|
||||
// .filter(|(k, _)| match_fn(k, match_string))
|
||||
// .map(|(k, _)| (k.clone(), ()))
|
||||
// .collect::<HashMap<String, ()>>(),
|
||||
// )
|
||||
// }
|
||||
|
||||
// ApplyFunc - returns a new set containing each value processed by 'apply_fn'.
|
||||
pub fn apply_func<F>(&self, apply_fn: F) -> StringSet
|
||||
where
|
||||
F: Fn(&str) -> String,
|
||||
{
|
||||
StringSet(
|
||||
self.0
|
||||
.iter()
|
||||
.map(|(k, _)| (apply_fn(k), ()))
|
||||
.collect::<HashMap<String, ()>>(),
|
||||
)
|
||||
}
|
||||
// // ApplyFunc - returns a new set containing each value processed by 'apply_fn'.
|
||||
// pub fn apply_func<F>(&self, apply_fn: F) -> StringSet
|
||||
// where
|
||||
// F: Fn(&str) -> String,
|
||||
// {
|
||||
// StringSet(
|
||||
// self.0
|
||||
// .iter()
|
||||
// .map(|(k, _)| (apply_fn(k), ()))
|
||||
// .collect::<HashMap<String, ()>>(),
|
||||
// )
|
||||
// }
|
||||
|
||||
// Equals - checks whether the given set is equal to the current set or not.
|
||||
pub fn equals(&self, other: &StringSet) -> bool {
|
||||
if self.0.len() != other.0.len() {
|
||||
return false;
|
||||
}
|
||||
self.0.iter().all(|(k, _)| other.0.contains_key(k))
|
||||
}
|
||||
// // Equals - checks whether the given set is equal to the current set or not.
|
||||
// pub fn equals(&self, other: &StringSet) -> bool {
|
||||
// if self.0.len() != other.0.len() {
|
||||
// return false;
|
||||
// }
|
||||
// self.0.iter().all(|(k, _)| other.0.contains_key(k))
|
||||
// }
|
||||
|
||||
// Intersection - returns the intersection with the given set as a new set.
|
||||
pub fn intersection(&self, other: &StringSet) -> StringSet {
|
||||
StringSet(
|
||||
self.0
|
||||
.iter()
|
||||
.filter(|(k, _)| other.0.contains_key::<String>(k))
|
||||
.map(|(k, _)| (k.clone(), ()))
|
||||
.collect::<HashMap<String, ()>>(),
|
||||
)
|
||||
}
|
||||
// // Intersection - returns the intersection with the given set as a new set.
|
||||
// pub fn intersection(&self, other: &StringSet) -> StringSet {
|
||||
// StringSet(
|
||||
// self.0
|
||||
// .iter()
|
||||
// .filter(|(k, _)| other.0.contains_key::<String>(k))
|
||||
// .map(|(k, _)| (k.clone(), ()))
|
||||
// .collect::<HashMap<String, ()>>(),
|
||||
// )
|
||||
// }
|
||||
|
||||
// Difference - returns the difference with the given set as a new set.
|
||||
pub fn difference(&self, other: &StringSet) -> StringSet {
|
||||
StringSet(
|
||||
self.0
|
||||
.iter()
|
||||
.filter(|(k, _)| !other.0.contains_key::<String>(k))
|
||||
.map(|(k, _)| (k.clone(), ()))
|
||||
.collect::<HashMap<String, ()>>(),
|
||||
)
|
||||
}
|
||||
// // Difference - returns the difference with the given set as a new set.
|
||||
// pub fn difference(&self, other: &StringSet) -> StringSet {
|
||||
// StringSet(
|
||||
// self.0
|
||||
// .iter()
|
||||
// .filter(|(k, _)| !other.0.contains_key::<String>(k))
|
||||
// .map(|(k, _)| (k.clone(), ()))
|
||||
// .collect::<HashMap<String, ()>>(),
|
||||
// )
|
||||
// }
|
||||
|
||||
// Union - returns the union with the given set as a new set.
|
||||
pub fn union(&self, other: &StringSet) -> StringSet {
|
||||
let mut new_set = self.clone();
|
||||
for (k, _) in other.0.iter() {
|
||||
new_set.0.insert(k.clone(), ());
|
||||
}
|
||||
new_set
|
||||
}
|
||||
}
|
||||
// // Union - returns the union with the given set as a new set.
|
||||
// pub fn union(&self, other: &StringSet) -> StringSet {
|
||||
// let mut new_set = self.clone();
|
||||
// for (k, _) in other.0.iter() {
|
||||
// new_set.0.insert(k.clone(), ());
|
||||
// }
|
||||
// new_set
|
||||
// }
|
||||
// }
|
||||
|
||||
// Implementing JSON serialization and deserialization would require the serde crate.
|
||||
// You would also need to implement Display and PartialEq traits for more idiomatic Rust.
|
||||
// // Implementing JSON serialization and deserialization would require the serde crate.
|
||||
// // You would also need to implement Display and PartialEq traits for more idiomatic Rust.
|
||||
|
||||
// Implementing Display trait to provide a string representation of the set.
|
||||
impl fmt::Display for StringSet {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.to_slice().join(", "))
|
||||
}
|
||||
}
|
||||
// // Implementing Display trait to provide a string representation of the set.
|
||||
// impl fmt::Display for StringSet {
|
||||
// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// write!(f, "{}", self.to_slice().join(", "))
|
||||
// }
|
||||
// }
|
||||
|
||||
// Implementing PartialEq and Eq traits to allow comparison of StringSet instances.
|
||||
impl PartialEq for StringSet {
|
||||
fn eq(&self, other: &StringSet) -> bool {
|
||||
self.equals(other)
|
||||
}
|
||||
}
|
||||
// // Implementing PartialEq and Eq traits to allow comparison of StringSet instances.
|
||||
// impl PartialEq for StringSet {
|
||||
// fn eq(&self, other: &StringSet) -> bool {
|
||||
// self.equals(other)
|
||||
// }
|
||||
// }
|
||||
|
||||
impl Eq for StringSet {}
|
||||
// impl Eq for StringSet {}
|
||||
|
||||
// NewStringSet - creates a new string set.
|
||||
pub fn new_string_set() -> StringSet {
|
||||
StringSet(HashMap::new())
|
||||
}
|
||||
// // NewStringSet - creates a new string set.
|
||||
// pub fn new_string_set() -> StringSet {
|
||||
// StringSet(HashMap::new())
|
||||
// }
|
||||
|
||||
// CreateStringSet - creates a new string set with given string values.
|
||||
pub fn create_string_set(sl: Vec<String>) -> StringSet {
|
||||
let mut set = new_string_set();
|
||||
for k in sl {
|
||||
set.add(k);
|
||||
}
|
||||
set
|
||||
}
|
||||
// // CreateStringSet - creates a new string set with given string values.
|
||||
// pub fn create_string_set(sl: Vec<String>) -> StringSet {
|
||||
// let mut set = new_string_set();
|
||||
// for k in sl {
|
||||
// set.add(k);
|
||||
// }
|
||||
// set
|
||||
// }
|
||||
|
||||
+17
-18
@@ -17,7 +17,6 @@ use s3s::{S3Request, S3Response};
|
||||
|
||||
use anyhow::Result;
|
||||
use ecstore::store::ECStore;
|
||||
use tracing::error;
|
||||
|
||||
macro_rules! try_ {
|
||||
($result:expr) => {
|
||||
@@ -54,14 +53,14 @@ impl S3 for FS {
|
||||
.await
|
||||
);
|
||||
|
||||
let output = CreateBucketOutput::default(); // TODO: handle other fields
|
||||
let output = CreateBucketOutput::default();
|
||||
Ok(S3Response::new(output))
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
async fn copy_object(&self, req: S3Request<CopyObjectInput>) -> S3Result<S3Response<CopyObjectOutput>> {
|
||||
let input = req.input;
|
||||
let (bucket, key) = match input.copy_source {
|
||||
let (_bucket, _key) = match input.copy_source {
|
||||
CopySource::AccessPoint { .. } => return Err(s3_error!(NotImplemented)),
|
||||
CopySource::Bucket { ref bucket, ref key, .. } => (bucket, key),
|
||||
};
|
||||
@@ -72,22 +71,22 @@ impl S3 for FS {
|
||||
|
||||
#[tracing::instrument]
|
||||
async fn delete_bucket(&self, req: S3Request<DeleteBucketInput>) -> S3Result<S3Response<DeleteBucketOutput>> {
|
||||
let input = req.input;
|
||||
let _input = req.input;
|
||||
|
||||
Ok(S3Response::new(DeleteBucketOutput {}))
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
async fn delete_object(&self, req: S3Request<DeleteObjectInput>) -> S3Result<S3Response<DeleteObjectOutput>> {
|
||||
let input = req.input;
|
||||
let _input = req.input;
|
||||
|
||||
let output = DeleteObjectOutput::default(); // TODO: handle other fields
|
||||
let output = DeleteObjectOutput::default();
|
||||
Ok(S3Response::new(output))
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
async fn delete_objects(&self, req: S3Request<DeleteObjectsInput>) -> S3Result<S3Response<DeleteObjectsOutput>> {
|
||||
let input = req.input;
|
||||
let _input = req.input;
|
||||
|
||||
let output = DeleteObjectsOutput { ..Default::default() };
|
||||
Ok(S3Response::new(output))
|
||||
@@ -146,7 +145,7 @@ impl S3 for FS {
|
||||
|
||||
#[tracing::instrument]
|
||||
async fn head_object(&self, req: S3Request<HeadObjectInput>) -> S3Result<S3Response<HeadObjectOutput>> {
|
||||
let input = req.input;
|
||||
let _input = req.input;
|
||||
|
||||
let output = HeadObjectOutput { ..Default::default() };
|
||||
Ok(S3Response::new(output))
|
||||
@@ -175,7 +174,7 @@ impl S3 for FS {
|
||||
|
||||
#[tracing::instrument]
|
||||
async fn list_objects_v2(&self, req: S3Request<ListObjectsV2Input>) -> S3Result<S3Response<ListObjectsV2Output>> {
|
||||
let input = req.input;
|
||||
let _input = req.input;
|
||||
|
||||
let output = ListObjectsV2Output { ..Default::default() };
|
||||
Ok(S3Response::new(output))
|
||||
@@ -196,7 +195,7 @@ impl S3 for FS {
|
||||
body,
|
||||
bucket,
|
||||
key,
|
||||
metadata,
|
||||
// metadata,
|
||||
content_length,
|
||||
..
|
||||
} = input;
|
||||
@@ -244,14 +243,14 @@ impl S3 for FS {
|
||||
async fn upload_part(&self, req: S3Request<UploadPartInput>) -> S3Result<S3Response<UploadPartOutput>> {
|
||||
let UploadPartInput {
|
||||
body,
|
||||
upload_id,
|
||||
part_number,
|
||||
// upload_id,
|
||||
// part_number,
|
||||
content_length,
|
||||
..
|
||||
} = req.input;
|
||||
|
||||
let body = body.ok_or_else(|| s3_error!(IncompleteBody))?;
|
||||
let content_length = content_length.ok_or_else(|| s3_error!(IncompleteBody))?;
|
||||
let _body = body.ok_or_else(|| s3_error!(IncompleteBody))?;
|
||||
let _content_length = content_length.ok_or_else(|| s3_error!(IncompleteBody))?;
|
||||
|
||||
// mc cp step 4
|
||||
|
||||
@@ -261,7 +260,7 @@ impl S3 for FS {
|
||||
|
||||
#[tracing::instrument]
|
||||
async fn upload_part_copy(&self, req: S3Request<UploadPartCopyInput>) -> S3Result<S3Response<UploadPartCopyOutput>> {
|
||||
let input = req.input;
|
||||
let _input = req.input;
|
||||
|
||||
let output = UploadPartCopyOutput { ..Default::default() };
|
||||
|
||||
@@ -289,10 +288,10 @@ impl S3 for FS {
|
||||
req: S3Request<CompleteMultipartUploadInput>,
|
||||
) -> S3Result<S3Response<CompleteMultipartUploadOutput>> {
|
||||
let CompleteMultipartUploadInput {
|
||||
multipart_upload,
|
||||
// multipart_upload,
|
||||
bucket,
|
||||
key,
|
||||
upload_id,
|
||||
// upload_id,
|
||||
..
|
||||
} = req.input;
|
||||
|
||||
@@ -307,7 +306,7 @@ impl S3 for FS {
|
||||
#[tracing::instrument]
|
||||
async fn abort_multipart_upload(
|
||||
&self,
|
||||
req: S3Request<AbortMultipartUploadInput>,
|
||||
_req: S3Request<AbortMultipartUploadInput>,
|
||||
) -> S3Result<S3Response<AbortMultipartUploadOutput>> {
|
||||
Ok(S3Response::new(AbortMultipartUploadOutput { ..Default::default() }))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user