Skip to content

Commit

Permalink
add clippy integration and fix the warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
iwanbk committed Jan 17, 2025
1 parent 9678018 commit 705d077
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@ jobs:
- name: Build
run: cargo build --features refcount

- uses: actions/checkout@v4
- name: Run clippy
run: cargo clippy --all-features -- -Dwarnings

- name: Run tests
run: cargo test --features refcount
10 changes: 5 additions & 5 deletions src/cas/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl CasFS {
for key in bucket.iter().keys() {
self.delete_object(
bucket_name,
std::str::from_utf8(&*key?).expect("keys are valid utf-8"),
std::str::from_utf8(&key?).expect("keys are valid utf-8"),
)
.await?;
}
Expand Down Expand Up @@ -168,7 +168,7 @@ impl CasFS {
// This is technically impossible
None => eprintln!(
"missing block {} in block map",
hex_string(&*block_id)
hex_string(block_id)
),
Some(block_data) => {
let mut block = Block::try_from(&*block_data)
Expand All @@ -180,11 +180,11 @@ impl CasFS {
// filled in by another block, before we properly delete the
// path from disk.
if block.rc() == 1 {
blocks.remove(&*block_id)?;
blocks.remove(block_id)?;
to_delete.push(block);
} else {
block.decrement_refcount();
blocks.insert(&*block_id, Vec::from(&block))?;
blocks.insert(block_id, Vec::from(&block))?;
}
}
}
Expand Down Expand Up @@ -228,7 +228,7 @@ impl CasFS {
pub fn buckets(&self) -> Result<Vec<Bucket>, sled::Error> {
Ok(self
.bucket_meta_tree()?
.scan_prefix(&[])
.scan_prefix([])
.values()
.filter_map(|raw_value| {
let value = match raw_value {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() -> Result<()> {

let args: Args = Args::from_args();

return run(args);
run(args)
}

use hyper_util::rt::{TokioExecutor, TokioIo};
Expand Down
50 changes: 25 additions & 25 deletions src/s3fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl S3 for S3FS {
multipart_upload
} else {
let err = s3_error!(InvalidPart, "Missing multipart_upload");
return Err(err.into());
return Err(err);
};

let multipart_map = try_!(self.casfs.multipart_tree());
Expand All @@ -119,7 +119,7 @@ impl S3 for S3FS {
Some(pde) => pde,
None => {
error!("Missing part \"{}\" in multipart upload", part_key);
return Err(s3_error!(InvalidArgument, "Part not uploaded").into());
return Err(s3_error!(InvalidArgument, "Part not uploaded"));
}
};

Expand All @@ -135,10 +135,10 @@ impl S3 for S3FS {
let mut size = 0;
let block_map = try_!(self.casfs.block_tree());
for block in &blocks {
let bi = try_!(block_map.get(&block)).unwrap(); // unwrap is fine as all blocks in must be present
let bi = try_!(block_map.get(block)).unwrap(); // unwrap is fine as all blocks in must be present
let block_info = Block::try_from(&*bi).expect("Block data is corrupt");
size += block_info.size();
hasher.update(&block);
hasher.update(block);
}
let e_tag = hasher.finalize().into();

Expand Down Expand Up @@ -187,14 +187,14 @@ impl S3 for S3FS {
};

if !try_!(self.casfs.bucket_exists(bucket)) {
return Err(s3_error!(NoSuchBucket, "Target bucket does not exist").into());
return Err(s3_error!(NoSuchBucket, "Target bucket does not exist"));
}

let source_bk = try_!(self.casfs.bucket(&input.bucket));
let mut obj_meta = match try_!(source_bk.get(&input.key)) {
// unwrap here is safe as it means the DB is corrupted
Some(enc_meta) => Object::try_from(&*enc_meta).unwrap(),
None => return Err(s3_error!(NoSuchKey, "Source key does not exist").into()),
None => return Err(s3_error!(NoSuchKey, "Source key does not exist")),
};

obj_meta.touch();
Expand Down Expand Up @@ -226,8 +226,7 @@ impl S3 for S3FS {
return Err(s3_error!(
BucketAlreadyExists,
"A bucket with this name already exists"
)
.into());
));
}

// TODO:
Expand Down Expand Up @@ -288,7 +287,7 @@ impl S3 for S3FS {
let DeleteObjectInput { bucket, key, .. } = req.input;

if !try_!(self.casfs.bucket_exists(&bucket)) {
return Err(s3_error!(NoSuchBucket, "Bucket does not exist").into());
return Err(s3_error!(NoSuchBucket, "Bucket does not exist"));
}

// TODO: check for the key existence?
Expand All @@ -307,7 +306,7 @@ impl S3 for S3FS {
let DeleteObjectsInput { bucket, delete, .. } = req.input;

if !try_!(self.casfs.bucket_exists(&bucket)) {
return Err(s3_error!(NoSuchBucket, "Bucket does not exist").into());
return Err(s3_error!(NoSuchBucket, "Bucket does not exist"));
}

let mut deleted_objects = Vec::with_capacity(delete.objects.len());
Expand Down Expand Up @@ -373,7 +372,7 @@ impl S3 for S3FS {
// load metadata
let bk = try_!(self.casfs.bucket(&bucket));
let obj = match try_!(bk.get(&key)) {
None => return Err(s3_error!(NoSuchKey, "The specified key does not exist").into()),
None => return Err(s3_error!(NoSuchKey, "The specified key does not exist")),
Some(obj) => obj,
};
let obj_meta = try_!(Object::try_from(&obj.to_vec()[..]));
Expand Down Expand Up @@ -423,7 +422,10 @@ impl S3 for S3FS {
let HeadBucketInput { bucket, .. } = req.input;

if !try_!(self.casfs.bucket_exists(&bucket)) {
return Err(s3_error!(NoSuchBucket, "The specified bucket does not exist").into());
return Err(s3_error!(
NoSuchBucket,
"The specified bucket does not exist"
));
}

Ok(S3Response::new(HeadBucketOutput::default()))
Expand All @@ -438,7 +440,7 @@ impl S3 for S3FS {

// TODO: move this to get_object_meta
let obj = match try_!(bk.get(&key)) {
None => return Err(s3_error!(NoSuchKey, "The specified key does not exist").into()),
None => return Err(s3_error!(NoSuchKey, "The specified key does not exist")),
Some(obj) => obj,
};
let obj_meta = try_!(Object::try_from(&obj.to_vec()[..]));
Expand Down Expand Up @@ -501,7 +503,7 @@ impl S3 for S3FS {
} else {
&[]
};
let prefix_bytes = prefix.as_deref().or(Some("")).unwrap().as_bytes();
let prefix_bytes = prefix.as_deref().unwrap_or("").as_bytes();

let mut objects = b
.range(start_bytes..)
Expand Down Expand Up @@ -576,15 +578,14 @@ impl S3 for S3FS {
let token = if let Some(ref rt) = continuation_token {
let mut out = vec![0; rt.len() / 2];
if hex_decode(rt.as_bytes(), &mut out).is_err() {
return Err(
s3_error!(InvalidToken, "continuation token has an invalid format").into(),
);
return Err(s3_error!(
InvalidToken,
"continuation token has an invalid format"
));
};
match String::from_utf8(out) {
Ok(s) => Some(s),
Err(_) => {
return Err(s3_error!(InvalidToken, "continuation token is invalid").into())
}
Err(_) => return Err(s3_error!(InvalidToken, "continuation token is invalid")),
}
} else {
None
Expand All @@ -599,7 +600,7 @@ impl S3 for S3FS {
} else {
&[]
};
let prefix_bytes = prefix.as_deref().or(Some("")).unwrap().as_bytes();
let prefix_bytes = prefix.as_deref().unwrap_or("").as_bytes();

let mut objects: Vec<_> = b
.range(start_bytes..)
Expand Down Expand Up @@ -642,7 +643,7 @@ impl S3 for S3FS {
max_keys: Some(key_count),
contents: Some(objects),
continuation_token,
delimiter: delimiter,
delimiter,
encoding_type,
name: Some(bucket),
prefix,
Expand Down Expand Up @@ -679,7 +680,7 @@ impl S3 for S3FS {
};

if !try_!(self.casfs.bucket_exists(&bucket)) {
return Err(s3_error!(NoSuchBucket, "Bucket does not exist").into());
return Err(s3_error!(NoSuchBucket, "Bucket does not exist"));
}

// save the data
Expand Down Expand Up @@ -733,8 +734,7 @@ impl S3 for S3FS {
return Err(s3_error!(
InvalidRequest,
"You did not send the amount of bytes specified by the Content-Length HTTP header."
)
.into());
));
}

let mp_map = try_!(self.casfs.multipart_tree());
Expand Down

0 comments on commit 705d077

Please sign in to comment.