Skip to content

Commit 705d077

Browse files
committed
add clippy integration and fix the warnings
1 parent 9678018 commit 705d077

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

.github/workflows/build.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@ jobs:
3434
- name: Build
3535
run: cargo build --features refcount
3636

37+
- uses: actions/checkout@v4
38+
- name: Run clippy
39+
run: cargo clippy --all-features -- -Dwarnings
40+
3741
- name: Run tests
3842
run: cargo test --features refcount

src/cas/fs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl CasFS {
128128
for key in bucket.iter().keys() {
129129
self.delete_object(
130130
bucket_name,
131-
std::str::from_utf8(&*key?).expect("keys are valid utf-8"),
131+
std::str::from_utf8(&key?).expect("keys are valid utf-8"),
132132
)
133133
.await?;
134134
}
@@ -168,7 +168,7 @@ impl CasFS {
168168
// This is technically impossible
169169
None => eprintln!(
170170
"missing block {} in block map",
171-
hex_string(&*block_id)
171+
hex_string(block_id)
172172
),
173173
Some(block_data) => {
174174
let mut block = Block::try_from(&*block_data)
@@ -180,11 +180,11 @@ impl CasFS {
180180
// filled in by another block, before we properly delete the
181181
// path from disk.
182182
if block.rc() == 1 {
183-
blocks.remove(&*block_id)?;
183+
blocks.remove(block_id)?;
184184
to_delete.push(block);
185185
} else {
186186
block.decrement_refcount();
187-
blocks.insert(&*block_id, Vec::from(&block))?;
187+
blocks.insert(block_id, Vec::from(&block))?;
188188
}
189189
}
190190
}
@@ -228,7 +228,7 @@ impl CasFS {
228228
pub fn buckets(&self) -> Result<Vec<Bucket>, sled::Error> {
229229
Ok(self
230230
.bucket_meta_tree()?
231-
.scan_prefix(&[])
231+
.scan_prefix([])
232232
.values()
233233
.filter_map(|raw_value| {
234234
let value = match raw_value {

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() -> Result<()> {
4444

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

47-
return run(args);
47+
run(args)
4848
}
4949

5050
use hyper_util::rt::{TokioExecutor, TokioIo};

src/s3fs.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl S3 for S3FS {
9595
multipart_upload
9696
} else {
9797
let err = s3_error!(InvalidPart, "Missing multipart_upload");
98-
return Err(err.into());
98+
return Err(err);
9999
};
100100

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

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

@@ -187,14 +187,14 @@ impl S3 for S3FS {
187187
};
188188

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

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

200200
obj_meta.touch();
@@ -226,8 +226,7 @@ impl S3 for S3FS {
226226
return Err(s3_error!(
227227
BucketAlreadyExists,
228228
"A bucket with this name already exists"
229-
)
230-
.into());
229+
));
231230
}
232231

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

290289
if !try_!(self.casfs.bucket_exists(&bucket)) {
291-
return Err(s3_error!(NoSuchBucket, "Bucket does not exist").into());
290+
return Err(s3_error!(NoSuchBucket, "Bucket does not exist"));
292291
}
293292

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

309308
if !try_!(self.casfs.bucket_exists(&bucket)) {
310-
return Err(s3_error!(NoSuchBucket, "Bucket does not exist").into());
309+
return Err(s3_error!(NoSuchBucket, "Bucket does not exist"));
311310
}
312311

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

425424
if !try_!(self.casfs.bucket_exists(&bucket)) {
426-
return Err(s3_error!(NoSuchBucket, "The specified bucket does not exist").into());
425+
return Err(s3_error!(
426+
NoSuchBucket,
427+
"The specified bucket does not exist"
428+
));
427429
}
428430

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

439441
// TODO: move this to get_object_meta
440442
let obj = match try_!(bk.get(&key)) {
441-
None => return Err(s3_error!(NoSuchKey, "The specified key does not exist").into()),
443+
None => return Err(s3_error!(NoSuchKey, "The specified key does not exist")),
442444
Some(obj) => obj,
443445
};
444446
let obj_meta = try_!(Object::try_from(&obj.to_vec()[..]));
@@ -501,7 +503,7 @@ impl S3 for S3FS {
501503
} else {
502504
&[]
503505
};
504-
let prefix_bytes = prefix.as_deref().or(Some("")).unwrap().as_bytes();
506+
let prefix_bytes = prefix.as_deref().unwrap_or("").as_bytes();
505507

506508
let mut objects = b
507509
.range(start_bytes..)
@@ -576,15 +578,14 @@ impl S3 for S3FS {
576578
let token = if let Some(ref rt) = continuation_token {
577579
let mut out = vec![0; rt.len() / 2];
578580
if hex_decode(rt.as_bytes(), &mut out).is_err() {
579-
return Err(
580-
s3_error!(InvalidToken, "continuation token has an invalid format").into(),
581-
);
581+
return Err(s3_error!(
582+
InvalidToken,
583+
"continuation token has an invalid format"
584+
));
582585
};
583586
match String::from_utf8(out) {
584587
Ok(s) => Some(s),
585-
Err(_) => {
586-
return Err(s3_error!(InvalidToken, "continuation token is invalid").into())
587-
}
588+
Err(_) => return Err(s3_error!(InvalidToken, "continuation token is invalid")),
588589
}
589590
} else {
590591
None
@@ -599,7 +600,7 @@ impl S3 for S3FS {
599600
} else {
600601
&[]
601602
};
602-
let prefix_bytes = prefix.as_deref().or(Some("")).unwrap().as_bytes();
603+
let prefix_bytes = prefix.as_deref().unwrap_or("").as_bytes();
603604

604605
let mut objects: Vec<_> = b
605606
.range(start_bytes..)
@@ -642,7 +643,7 @@ impl S3 for S3FS {
642643
max_keys: Some(key_count),
643644
contents: Some(objects),
644645
continuation_token,
645-
delimiter: delimiter,
646+
delimiter,
646647
encoding_type,
647648
name: Some(bucket),
648649
prefix,
@@ -679,7 +680,7 @@ impl S3 for S3FS {
679680
};
680681

681682
if !try_!(self.casfs.bucket_exists(&bucket)) {
682-
return Err(s3_error!(NoSuchBucket, "Bucket does not exist").into());
683+
return Err(s3_error!(NoSuchBucket, "Bucket does not exist"));
683684
}
684685

685686
// save the data
@@ -733,8 +734,7 @@ impl S3 for S3FS {
733734
return Err(s3_error!(
734735
InvalidRequest,
735736
"You did not send the amount of bytes specified by the Content-Length HTTP header."
736-
)
737-
.into());
737+
));
738738
}
739739

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

0 commit comments

Comments
 (0)