fix: 优化警告代码

This commit is contained in:
shiro.lee
2024-08-06 09:31:48 +08:00
parent 669808069d
commit 7dacc47f16
9 changed files with 53 additions and 73 deletions
+10 -10
View File
@@ -24,11 +24,11 @@ use uuid::Uuid;
pub struct LocalDisk {
pub root: PathBuf,
pub id: Uuid,
pub format_data: Vec<u8>,
pub format_meta: Option<Metadata>,
pub format_path: PathBuf,
pub _format_data: Vec<u8>,
pub _format_meta: Option<Metadata>,
pub _format_path: PathBuf,
// pub format_legacy: bool, // drop
pub format_last_check: OffsetDateTime,
pub _format_last_check: OffsetDateTime,
}
impl LocalDisk {
@@ -67,11 +67,11 @@ impl LocalDisk {
let disk = Self {
root,
id,
format_meta,
format_data,
format_path,
_format_meta: format_meta,
_format_data: format_data,
_format_path: format_path,
// format_legacy,
format_last_check,
_format_last_check: format_last_check,
};
disk.make_meta_volumes().await?;
@@ -463,7 +463,7 @@ impl DiskAPI for LocalDisk {
// Ok((buffer, bytes_read))
}
async fn list_dir(&self, origvolume: &str, volume: &str, dir_path: &str, count: usize) -> Result<Vec<String>> {
async fn list_dir(&self, _origvolume: &str, volume: &str, _dir_path: &str, _count: usize) -> Result<Vec<String>> {
let p = self.get_bucket_path(volume)?;
let mut entries = fs::read_dir(&p).await?;
@@ -471,7 +471,7 @@ impl DiskAPI for LocalDisk {
let mut volumes = Vec::new();
while let Some(entry) = entries.next_entry().await? {
if let Ok(metadata) = entry.metadata().await {
if let Ok(_metadata) = entry.metadata().await {
// if !metadata.is_dir() {
// continue;
// }
+15 -19
View File
@@ -17,10 +17,10 @@ use crate::disk::FileReader;
pub struct Erasure {
data_shards: usize,
parity_shards: usize,
_parity_shards: usize,
encoder: ReedSolomon,
block_size: usize,
id: Uuid,
_id: Uuid,
}
impl Erasure {
@@ -31,17 +31,17 @@ impl Erasure {
);
Erasure {
data_shards,
parity_shards,
_parity_shards: parity_shards,
block_size,
encoder: ReedSolomon::new(data_shards, parity_shards).unwrap(),
id: Uuid::new_v4(),
_id: Uuid::new_v4(),
}
}
pub async fn encode<S, W>(
&self,
body: S,
writers: &mut Vec<W>,
writers: &mut [W],
// block_size: usize,
total_size: usize,
_write_quorum: usize,
@@ -134,21 +134,16 @@ impl Erasure {
let mut bytes_writed = 0;
for block_idx in start_block..=end_block {
let mut block_offset = 0;
let mut block_length = 0;
if start_block == end_block {
block_offset = offset % self.block_size;
block_length = length;
let (block_offset, block_length) = if start_block == end_block {
(offset % self.block_size, length)
} else if block_idx == start_block {
block_offset = offset % self.block_size;
block_length = self.block_size - block_offset;
let block_offset = offset % self.block_size;
(block_offset, self.block_size - block_offset)
} else if block_idx == end_block {
block_offset = 0;
block_length = (offset + length) % self.block_size;
(0, (offset + length) % self.block_size)
} else {
block_offset = 0;
block_length = self.block_size;
}
(0, self.block_size)
};
if block_length == 0 {
// debug!("block_length == 0 break");
@@ -272,7 +267,7 @@ impl Erasure {
Ok(shards)
}
pub fn decode_data(&self, shards: &mut Vec<Option<Vec<u8>>>) -> Result<()> {
pub fn decode_data(&self, shards: &mut [Option<Vec<u8>>]) -> Result<()> {
self.encoder.reconstruct(shards)?;
Ok(())
}
@@ -385,7 +380,8 @@ impl ShardReader {
Ok(ress)
}
fn can_decode(&self, bufs: &Vec<Option<Vec<u8>>>) -> bool {
fn can_decode(&self, bufs: &[Option<Vec<u8>>]) -> bool {
bufs.iter().filter(|v| v.is_some()).count() > self.data_block_count
}
}
+4 -4
View File
@@ -202,7 +202,7 @@ impl PeerS3Client for S3PeerSys {
}
ress.iter()
.find_map(|op| op.as_ref().map(|v| v.clone()))
.find_map(|op| op.clone())
.ok_or(Error::new(DiskError::VolumeNotFound))
}
@@ -233,7 +233,7 @@ impl PeerS3Client for LocalPeerS3Client {
fn get_pools(&self) -> Vec<usize> {
self.pools.clone()
}
async fn list_bucket(&self, opts: &BucketOptions) -> Result<Vec<BucketInfo>> {
async fn list_bucket(&self, _opts: &BucketOptions) -> Result<Vec<BucketInfo>> {
let mut futures = Vec::with_capacity(self.local_disks.len());
for disk in self.local_disks.iter() {
futures.push(disk.list_volumes());
@@ -390,7 +390,7 @@ impl PeerS3Client for RemotePeerS3Client {
fn get_pools(&self) -> Vec<usize> {
unimplemented!()
}
async fn list_bucket(&self, opts: &BucketOptions) -> Result<Vec<BucketInfo>> {
async fn list_bucket(&self, _opts: &BucketOptions) -> Result<Vec<BucketInfo>> {
unimplemented!()
}
async fn make_bucket(&self, _bucket: &str, _opts: &MakeBucketOptions) -> Result<()> {
@@ -400,7 +400,7 @@ impl PeerS3Client for RemotePeerS3Client {
unimplemented!()
}
async fn delete_bucket(&self, bucket: &str) -> Result<()> {
async fn delete_bucket(&self, _bucket: &str) -> Result<()> {
unimplemented!()
}
}
+5 -5
View File
@@ -8,8 +8,8 @@ use crate::{
error::Result,
set_disk::SetDisks,
store_api::{
BucketInfo, BucketOptions, CompletePart, FileInfo, GetObjectReader, HTTPRangeSpec, MakeBucketOptions,
MultipartUploadResult, ObjectInfo, ObjectOptions, PartInfo, PutObjReader, StorageAPI,
BucketInfo, BucketOptions, CompletePart, GetObjectReader, HTTPRangeSpec, MakeBucketOptions, MultipartUploadResult,
ObjectInfo, ObjectOptions, PartInfo, PutObjReader, StorageAPI,
},
utils::hash,
};
@@ -66,7 +66,7 @@ impl Sets {
}
let sets = Self {
id: fm.id.clone(),
id: fm.id,
// sets: todo!(),
disk_set,
pool_idx,
@@ -122,7 +122,7 @@ impl Sets {
#[async_trait::async_trait]
impl StorageAPI for Sets {
async fn list_bucket(&self, opts: &BucketOptions) -> Result<Vec<BucketInfo>> {
async fn list_bucket(&self, _opts: &BucketOptions) -> Result<Vec<BucketInfo>> {
unimplemented!()
}
async fn make_bucket(&self, _bucket: &str, _opts: &MakeBucketOptions) -> Result<()> {
@@ -187,7 +187,7 @@ impl StorageAPI for Sets {
.await
}
async fn delete_bucket(&self, bucket: &str) -> Result<()> {
async fn delete_bucket(&self, _bucket: &str) -> Result<()> {
unimplemented!()
}
}
+1 -1
View File
@@ -68,7 +68,7 @@ impl ECStore {
.await?;
if deployment_id.is_none() {
deployment_id = Some(fm.id.clone());
deployment_id = Some(fm.id);
}
if deployment_id != Some(fm.id) {
+11 -13
View File
@@ -4,8 +4,6 @@ use rmp_serde::Serializer;
use s3s::dto::StreamingBlob;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use tokio::io::{AsyncRead, DuplexStream};
use tracing::warn;
use uuid::Uuid;
pub const ERASURE_ALGORITHM: &str = "rs-vandermonde";
@@ -56,7 +54,7 @@ impl FileInfo {
}
pub fn unmarshal(buf: &[u8]) -> Result<Self> {
let t: FileInfo = rmp_serde::from_slice(&buf)?;
let t: FileInfo = rmp_serde::from_slice(buf)?;
Ok(t)
}
@@ -80,7 +78,7 @@ impl FileInfo {
self.parts.sort_by(|a, b| a.number.cmp(&b.number));
}
pub fn into_object_info(&self, bucket: &str, object: &str, versioned: bool) -> ObjectInfo {
pub fn into_object_info(&self, bucket: &str, object: &str, _versioned: bool) -> ObjectInfo {
ObjectInfo {
bucket: bucket.to_string(),
name: object.to_string(),
@@ -151,8 +149,8 @@ impl FileInfo {
Self {
erasure: ErasureInfo {
algorithm: String::from(ERASURE_ALGORITHM),
data_blocks: data_blocks,
parity_blocks: parity_blocks,
data_blocks,
parity_blocks,
block_size: BLOCK_SIZE_V2,
distribution: indexs,
..Default::default()
@@ -272,7 +270,7 @@ pub struct GetObjectReader {
// }
pub struct HTTPRangeSpec {
pub is_shuffix_length: bool,
pub is_suffix_length: bool,
pub start: i64,
pub end: i64,
}
@@ -280,7 +278,7 @@ pub struct HTTPRangeSpec {
impl HTTPRangeSpec {
pub fn nil() -> Self {
Self {
is_shuffix_length: false,
is_suffix_length: false,
start: -1,
end: -1,
}
@@ -303,9 +301,9 @@ impl HTTPRangeSpec {
}
HTTPRangeSpec {
is_shuffix_length: false,
start: start,
end: end,
is_suffix_length: false,
start,
end,
}
}
@@ -316,7 +314,7 @@ impl HTTPRangeSpec {
let len = self.get_length(res_size)?;
let mut start = self.start;
if self.is_shuffix_length {
if self.is_suffix_length {
start = self.start + res_size
}
Ok((start, len))
@@ -326,7 +324,7 @@ impl HTTPRangeSpec {
return Ok(res_size);
}
if self.is_shuffix_length {
if self.is_suffix_length {
let specified_len = -self.start; // 假设 h.start 是一个 i64 类型
let mut range_length = specified_len;
+2 -2
View File
@@ -10,13 +10,13 @@ pub fn hex(data: impl AsRef<[u8]>) -> String {
hex_simd::encode_to_string(data, hex_simd::AsciiCase::Lower)
}
#[cfg(not(all(feature = "openssl", not(windows))))]
#[cfg(windows)]
pub fn sha256(data: &[u8]) -> impl AsRef<[u8; 32]> {
use sha2::{Digest, Sha256};
<Sha256 as Digest>::digest(data)
}
#[cfg(all(feature = "openssl", not(windows)))]
#[cfg(not(windows))]
pub fn sha256(data: &[u8]) -> impl AsRef<[u8]> {
use openssl::hash::{Hasher, MessageDigest};
let mut h = Hasher::new(MessageDigest::sha256()).unwrap();
+1
View File
@@ -18,6 +18,7 @@ pub fn encode_dir_object(object: &str) -> String {
}
}
#[allow(dead_code)]
pub fn decode_dir_object(object: &str) -> String {
if has_suffix(object, GLOBAL_DIR_SUFFIX) {
format!("{}{}", object.trim_end_matches(GLOBAL_DIR_SUFFIX), SLASH_SEPARATOR)
+4 -19
View File
@@ -193,23 +193,7 @@ impl S3 for FS {
#[tracing::instrument(level = "debug", skip(self, req))]
async fn head_object(&self, req: S3Request<HeadObjectInput>) -> S3Result<S3Response<HeadObjectOutput>> {
// mc get 2
let HeadObjectInput {
bucket,
checksum_mode,
expected_bucket_owner,
if_match,
if_modified_since,
if_none_match,
if_unmodified_since,
key,
part_number,
range,
request_payer,
sse_customer_algorithm,
sse_customer_key,
sse_customer_key_md5,
version_id,
} = req.input;
let HeadObjectInput { bucket, key, .. } = req.input;
let info = try_!(self.store.get_object_info(&bucket, &key, &ObjectOptions::default()).await);
debug!("info {:?}", info);
@@ -297,7 +281,7 @@ impl S3 for FS {
let Some(content_length) = content_length else { return Err(s3_error!(IncompleteBody)) };
let reader = PutObjReader::new(body.into(), content_length as usize);
let reader = PutObjReader::new(body, content_length as usize);
try_!(self.store.put_object(&bucket, &key, reader, &ObjectOptions::default()).await);
@@ -356,7 +340,7 @@ impl S3 for FS {
let content_length = content_length.ok_or_else(|| s3_error!(IncompleteBody))?;
// mc cp step 4
let data = PutObjReader::new(body.into(), content_length as usize);
let data = PutObjReader::new(body, content_length as usize);
let opts = ObjectOptions::default();
try_!(
@@ -451,6 +435,7 @@ impl S3 for FS {
}
}
#[allow(dead_code)]
pub fn bytes_stream<S, E>(stream: S, content_length: usize) -> impl Stream<Item = Result<Bytes, E>> + Send + 'static
where
S: Stream<Item = Result<Bytes, E>> + Send + 'static,