chore: clean relative to references and borrows

- lint message: the borrowed expression implements the required traits
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#needless_borrows_for_generic_args
- lint message: this expression creates a reference which is immediately dereferenced by the compiler
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#needless_borrow
- lint message: you don't need to add `&` to all patterns
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#match_ref_pat
- remove useless taken reference
lint message: needlessly taken reference of left operand
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#op_ref
- use &Path instead of &PathBuf as fn parameters
lint message: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#ptr_arg
This commit is contained in:
Gwen Lg
2025-12-13 17:43:05 +01:00
parent 209263eb93
commit 141b3f24f1
35 changed files with 129 additions and 134 deletions
+3 -3
View File
@@ -143,7 +143,7 @@ impl RequestHandler for UpdateAdminTokenRequest {
garage: &Arc<Garage>,
_admin: &Admin,
) -> Result<UpdateAdminTokenResponse, Error> {
let mut token = get_existing_admin_token(&garage, &self.id).await?;
let mut token = get_existing_admin_token(garage, &self.id).await?;
apply_token_updates(&mut token, self.body)?;
@@ -164,7 +164,7 @@ impl RequestHandler for DeleteAdminTokenRequest {
garage: &Arc<Garage>,
_admin: &Admin,
) -> Result<DeleteAdminTokenResponse, Error> {
let token = get_existing_admin_token(&garage, &self.id).await?;
let token = get_existing_admin_token(garage, &self.id).await?;
garage
.admin_token_table
@@ -224,7 +224,7 @@ impl RequestHandler for GetCurrentAdminTokenInfoRequest {
}
let (prefix, _) = self.admin_token.split_once('.').unwrap();
let token = get_existing_admin_token(&garage, &prefix.to_string()).await?;
let token = get_existing_admin_token(garage, &prefix.to_string()).await?;
Ok(GetCurrentAdminTokenInfoResponse(admin_token_info_results(
&token, now,
+7 -7
View File
@@ -64,7 +64,7 @@ impl EndpointHandler<AdminRpc> for AdminApiServer {
match message {
AdminRpc::Proxy(req) => {
info!("Proxied admin API request: {}", req.name());
let res = req.clone().handle(&self.garage, &self).await;
let res = req.clone().handle(&self.garage, self).await;
match res {
Ok(res) => Ok(AdminRpcResponse::ProxyApiOkResponse(res.tagged())),
Err(e) => Ok(AdminRpcResponse::ApiErrorResponse {
@@ -76,7 +76,7 @@ impl EndpointHandler<AdminRpc> for AdminApiServer {
}
AdminRpc::Internal(req) => {
info!("Internal admin API request: {}", req.name());
let res = req.clone().handle(&self.garage, &self).await;
let res = req.clone().handle(&self.garage, self).await;
match res {
Ok(res) => Ok(AdminRpcResponse::InternalApiOkResponse(res)),
Err(e) => Ok(AdminRpcResponse::ApiErrorResponse {
@@ -173,12 +173,12 @@ impl AdminApiServer {
}
match request {
AdminApiRequest::Options(req) => req.handle(&self.garage, &self).await,
AdminApiRequest::CheckDomain(req) => req.handle(&self.garage, &self).await,
AdminApiRequest::Health(req) => req.handle(&self.garage, &self).await,
AdminApiRequest::Metrics(req) => req.handle(&self.garage, &self).await,
AdminApiRequest::Options(req) => req.handle(&self.garage, self).await,
AdminApiRequest::CheckDomain(req) => req.handle(&self.garage, self).await,
AdminApiRequest::Health(req) => req.handle(&self.garage, self).await,
AdminApiRequest::Metrics(req) => req.handle(&self.garage, self).await,
req => {
let res = req.handle(&self.garage, &self).await?;
let res = req.handle(&self.garage, self).await?;
let mut res = json_ok_response(&res)?;
res.headers_mut()
.insert(ACCESS_CONTROL_ALLOW_ORIGIN, HeaderValue::from_static("*"));
+9 -9
View File
@@ -29,7 +29,7 @@ impl RequestHandler for LocalListBlockErrorsRequest {
let errors = errors
.into_iter()
.map(|e| BlockError {
block_hash: hex::encode(&e.hash),
block_hash: hex::encode(e.hash),
refcount: e.refcount,
error_count: e.error_count,
last_try_secs_ago: now.saturating_sub(e.last_try) / 1000,
@@ -61,15 +61,15 @@ impl RequestHandler for LocalGetBlockInfoRequest {
VersionBacklink::MultipartUpload { upload_id } => {
if let Some(u) = garage.mpu_table.get(upload_id, &EmptyKey).await? {
BlockVersionBacklink::Upload {
upload_id: hex::encode(&upload_id),
upload_id: hex::encode(upload_id),
upload_deleted: u.deleted.get(),
upload_garbage_collected: false,
bucket_id: Some(hex::encode(&u.bucket_id)),
bucket_id: Some(hex::encode(u.bucket_id)),
key: Some(u.key.to_string()),
}
} else {
BlockVersionBacklink::Upload {
upload_id: hex::encode(&upload_id),
upload_id: hex::encode(upload_id),
upload_deleted: true,
upload_garbage_collected: true,
bucket_id: None,
@@ -78,12 +78,12 @@ impl RequestHandler for LocalGetBlockInfoRequest {
}
}
VersionBacklink::Object { bucket_id, key } => BlockVersionBacklink::Object {
bucket_id: hex::encode(&bucket_id),
bucket_id: hex::encode(bucket_id),
key: key.to_string(),
},
};
versions.push(BlockVersion {
version_id: hex::encode(&br.version),
version_id: hex::encode(br.version),
ref_deleted: br.deleted.get(),
version_deleted: v.deleted.get(),
garbage_collected: false,
@@ -91,7 +91,7 @@ impl RequestHandler for LocalGetBlockInfoRequest {
});
} else {
versions.push(BlockVersion {
version_id: hex::encode(&br.version),
version_id: hex::encode(br.version),
ref_deleted: br.deleted.get(),
version_deleted: true,
garbage_collected: true,
@@ -100,7 +100,7 @@ impl RequestHandler for LocalGetBlockInfoRequest {
}
}
Ok(LocalGetBlockInfoResponse {
block_hash: hex::encode(&hash),
block_hash: hex::encode(hash),
refcount,
versions,
})
@@ -215,7 +215,7 @@ fn find_block_hash_by_prefix(garage: &Arc<Garage>, prefix: &str) -> Result<Hash,
for item in iter {
let (k, _v) = item.map_err(GarageError::from)?;
let hash = Hash::try_from(&k[..32]).unwrap();
if &hash.as_slice()[..prefix_bin.len()] != prefix_bin {
if hash.as_slice()[..prefix_bin.len()] != prefix_bin {
break;
}
if hex::encode(hash.as_slice()).starts_with(prefix) {
+3 -3
View File
@@ -380,13 +380,13 @@ impl RequestHandler for InspectObjectRequest {
.map(|(vk, vb)| InspectObjectBlock {
part_number: vk.part_number,
offset: vk.offset,
hash: hex::encode(&vb.hash),
hash: hex::encode(vb.hash),
size: vb.size,
})
.collect::<Vec<_>>()
})
.unwrap_or_default();
let uuid = hex::encode(&obj_ver.uuid);
let uuid = hex::encode(obj_ver.uuid);
let timestamp = DateTime::from_timestamp_millis(obj_ver.timestamp as i64)
.expect("invalid timestamp in db");
match &obj_ver.state {
@@ -467,7 +467,7 @@ impl RequestHandler for InspectObjectRequest {
}
Ok(InspectObjectResponse {
bucket_id: hex::encode(&object.bucket_id),
bucket_id: hex::encode(object.bucket_id),
key: object.key,
versions,
})
+1 -1
View File
@@ -143,7 +143,7 @@ impl RequestHandler for GetClusterLayoutHistoryRequest {
.iter()
.map(|node| {
(
hex::encode(&node),
hex::encode(node),
NodeUpdateTrackers {
ack: layout.update_trackers.ack_map.get(node, min_stored),
sync: layout.update_trackers.sync_map.get(node, min_stored),
+11 -11
View File
@@ -187,7 +187,7 @@ impl Checksums {
pub fn verify(&self, expected: &ExpectedChecksums) -> Result<(), Error> {
if let Some(expected_md5) = &expected.md5 {
match self.md5 {
Some(md5) if BASE64_STANDARD.encode(&md5) == expected_md5.trim_matches('"') => (),
Some(md5) if BASE64_STANDARD.encode(md5) == expected_md5.trim_matches('"') => (),
_ => {
return Err(Error::InvalidDigest(
"MD5 checksum verification failed (from content-md5)".into(),
@@ -312,7 +312,7 @@ pub fn extract_checksum_value(
ChecksumAlgorithm::Crc32 => {
let crc32 = headers
.get(X_AMZ_CHECKSUM_CRC32)
.and_then(|x| BASE64_STANDARD.decode(&x).ok())
.and_then(|x| BASE64_STANDARD.decode(x).ok())
.and_then(|x| x.try_into().ok())
.ok_or_bad_request("invalid x-amz-checksum-crc32 header")?;
Ok(ChecksumValue::Crc32(crc32))
@@ -320,7 +320,7 @@ pub fn extract_checksum_value(
ChecksumAlgorithm::Crc32c => {
let crc32c = headers
.get(X_AMZ_CHECKSUM_CRC32C)
.and_then(|x| BASE64_STANDARD.decode(&x).ok())
.and_then(|x| BASE64_STANDARD.decode(x).ok())
.and_then(|x| x.try_into().ok())
.ok_or_bad_request("invalid x-amz-checksum-crc32c header")?;
Ok(ChecksumValue::Crc32c(crc32c))
@@ -328,7 +328,7 @@ pub fn extract_checksum_value(
ChecksumAlgorithm::Crc64Nvme => {
let crc64nvme = headers
.get(X_AMZ_CHECKSUM_CRC64NVME)
.and_then(|x| BASE64_STANDARD.decode(&x).ok())
.and_then(|x| BASE64_STANDARD.decode(x).ok())
.and_then(|x| x.try_into().ok())
.ok_or_bad_request("invalid x-amz-checksum-crc64nvme header")?;
Ok(ChecksumValue::Crc64Nvme(crc64nvme))
@@ -336,7 +336,7 @@ pub fn extract_checksum_value(
ChecksumAlgorithm::Sha1 => {
let sha1 = headers
.get(X_AMZ_CHECKSUM_SHA1)
.and_then(|x| BASE64_STANDARD.decode(&x).ok())
.and_then(|x| BASE64_STANDARD.decode(x).ok())
.and_then(|x| x.try_into().ok())
.ok_or_bad_request("invalid x-amz-checksum-sha1 header")?;
Ok(ChecksumValue::Sha1(sha1))
@@ -344,7 +344,7 @@ pub fn extract_checksum_value(
ChecksumAlgorithm::Sha256 => {
let sha256 = headers
.get(X_AMZ_CHECKSUM_SHA256)
.and_then(|x| BASE64_STANDARD.decode(&x).ok())
.and_then(|x| BASE64_STANDARD.decode(x).ok())
.and_then(|x| x.try_into().ok())
.ok_or_bad_request("invalid x-amz-checksum-sha256 header")?;
Ok(ChecksumValue::Sha256(sha256))
@@ -358,19 +358,19 @@ pub fn add_checksum_response_headers(
) -> http::response::Builder {
match checksum {
Some(ChecksumValue::Crc32(crc32)) => {
resp = resp.header(X_AMZ_CHECKSUM_CRC32, BASE64_STANDARD.encode(&crc32));
resp = resp.header(X_AMZ_CHECKSUM_CRC32, BASE64_STANDARD.encode(crc32));
}
Some(ChecksumValue::Crc32c(crc32c)) => {
resp = resp.header(X_AMZ_CHECKSUM_CRC32C, BASE64_STANDARD.encode(&crc32c));
resp = resp.header(X_AMZ_CHECKSUM_CRC32C, BASE64_STANDARD.encode(crc32c));
}
Some(ChecksumValue::Crc64Nvme(crc64nvme)) => {
resp = resp.header(X_AMZ_CHECKSUM_CRC64NVME, BASE64_STANDARD.encode(&crc64nvme));
resp = resp.header(X_AMZ_CHECKSUM_CRC64NVME, BASE64_STANDARD.encode(crc64nvme));
}
Some(ChecksumValue::Sha1(sha1)) => {
resp = resp.header(X_AMZ_CHECKSUM_SHA1, BASE64_STANDARD.encode(&sha1));
resp = resp.header(X_AMZ_CHECKSUM_SHA1, BASE64_STANDARD.encode(sha1));
}
Some(ChecksumValue::Sha256(sha256)) => {
resp = resp.header(X_AMZ_CHECKSUM_SHA256, BASE64_STANDARD.encode(&sha256));
resp = resp.header(X_AMZ_CHECKSUM_SHA256, BASE64_STANDARD.encode(sha256));
}
None => (),
}
+1 -1
View File
@@ -69,7 +69,7 @@ pub fn verify_request(
mut req: Request<IncomingBody>,
service: &'static str,
) -> Result<VerifiedRequest, Error> {
let checked_signature = payload::check_payload_signature(&garage, &mut req, service)?;
let checked_signature = payload::check_payload_signature(garage, &mut req, service)?;
let request = streaming::parse_streaming_body(
req,
+2 -2
View File
@@ -187,7 +187,7 @@ fn check_presigned_signature(
let headers_mut = request.headers_mut();
for (name, value) in query.iter() {
if let Some(existing) = headers_mut.get(name) {
if signed_headers.contains(&name) && existing.as_bytes() != value.value.as_bytes() {
if signed_headers.contains(name) && existing.as_bytes() != value.value.as_bytes() {
return Err(Error::bad_request(format!(
"Conflicting values for `{}` in query parameters and request headers",
name
@@ -343,7 +343,7 @@ pub fn canonical_request(
let canonical_query_string = {
let mut items = Vec::with_capacity(query.len());
for (_, QueryValue { key, value }) in query.iter() {
items.push(uri_encode(&key, true) + "=" + &uri_encode(&value, true));
items.push(uri_encode(key, true) + "=" + &uri_encode(value, true));
}
items.sort();
items.join("&")
+1 -1
View File
@@ -33,7 +33,7 @@ pub async fn handle_read_index(
let (partition_keys, more, next_start) = read_range(
&garage.k2v.counter_table.table,
&bucket_id,
bucket_id,
&prefix,
&start,
&end,
+4 -4
View File
@@ -57,23 +57,23 @@ pub fn handle_get_bucket_acl(ctx: ReqCtx) -> Result<Response<ResBody>, Error> {
if kp.allow_owner {
grants.push(s3_xml::Grant {
grantee: create_grantee(&key_p, &api_key),
grantee: create_grantee(key_p, &api_key),
permission: s3_xml::Value("FULL_CONTROL".to_string()),
});
} else {
if kp.allow_read {
grants.push(s3_xml::Grant {
grantee: create_grantee(&key_p, &api_key),
grantee: create_grantee(key_p, &api_key),
permission: s3_xml::Value("READ".to_string()),
});
grants.push(s3_xml::Grant {
grantee: create_grantee(&key_p, &api_key),
grantee: create_grantee(key_p, &api_key),
permission: s3_xml::Value("READ_ACP".to_string()),
});
}
if kp.allow_write {
grants.push(s3_xml::Grant {
grantee: create_grantee(&key_p, &api_key),
grantee: create_grantee(key_p, &api_key),
permission: s3_xml::Value("WRITE".to_string()),
});
}
+8 -8
View File
@@ -124,7 +124,7 @@ impl EncryptionParams {
pub fn add_response_headers(&self, resp: &mut http::response::Builder) {
if let Self::SseC { client_key_md5, .. } = self {
let md5 = BASE64_STANDARD.encode(&client_key_md5);
let md5 = BASE64_STANDARD.encode(client_key_md5);
resp.headers_mut().unwrap().insert(
X_AMZ_SERVER_SIDE_ENCRYPTION_CUSTOMER_ALGORITHM,
@@ -196,7 +196,7 @@ impl EncryptionParams {
None
},
};
let plaintext = enc.decrypt_blob(&inner)?;
let plaintext = enc.decrypt_blob(inner)?;
let inner = ObjectVersionMetaInner::decode(&plaintext)
.ok_or_internal_error("Could not decode encrypted metadata")?;
Ok((enc, Cow::Owned(inner)))
@@ -248,7 +248,7 @@ impl EncryptionParams {
// So we just put some random bytes.
let mut random = [0u8; 16];
OsRng.fill_bytes(&mut random);
hex::encode(&random)
hex::encode(random)
}
}
}
@@ -263,12 +263,12 @@ impl EncryptionParams {
Self::SseC {
object_key: Some(oek),
..
} => Some(Aes256Gcm::new(&oek)),
} => Some(Aes256Gcm::new(oek)),
Self::SseC {
client_key,
object_key: None,
..
} => Some(Aes256Gcm::new(&client_key)),
} => Some(Aes256Gcm::new(client_key)),
Self::Plaintext => None,
}
}
@@ -433,7 +433,7 @@ fn parse_request_headers(
let key_b64 =
key.ok_or_bad_request("Missing server-side-encryption-customer-key header")?;
let key_bytes: [u8; 32] = BASE64_STANDARD
.decode(&key_b64)
.decode(key_b64)
.ok_or_bad_request(
"Invalid server-side-encryption-customer-key header: invalid base64",
)?
@@ -445,7 +445,7 @@ fn parse_request_headers(
let md5_b64 =
md5.ok_or_bad_request("Missing server-side-encryption-customer-key-md5 header")?;
let md5_bytes = BASE64_STANDARD.decode(&md5_b64).ok_or_bad_request(
let md5_bytes = BASE64_STANDARD.decode(md5_b64).ok_or_bad_request(
"Invalid server-side-encryption-customer-key-md5 header: invalid bass64",
)?;
@@ -547,7 +547,7 @@ impl Stream for DecryptStream {
let nonce_size = StreamNonceSize::to_usize();
if let Some(nonce) = this.buf.take_exact(nonce_size) {
let nonce = Nonce::from_slice(nonce.as_ref());
*this.state = DecryptStreamState::Running(DecryptorLE31::new(&this.key, nonce));
*this.state = DecryptStreamState::Running(DecryptorLE31::new(this.key, nonce));
break;
}
+6 -6
View File
@@ -124,7 +124,7 @@ fn handle_http_precondition(
) -> Result<Option<Response<ResBody>>, Error> {
let precondition_headers = PreconditionHeaders::parse(req)?;
if let Some(status_code) = precondition_headers.check(&version, &version_meta.etag)? {
if let Some(status_code) = precondition_headers.check(version, &version_meta.etag)? {
Ok(Some(
Response::builder()
.status(status_code)
@@ -189,7 +189,7 @@ pub async fn handle_head_without_ctx(
OekDerivationInfo::for_object(&object, object_version),
)?;
let checksum_mode = checksum_mode(&req);
let checksum_mode = checksum_mode(req);
if let Some(part_number) = part_number {
match version_data {
@@ -316,7 +316,7 @@ pub async fn handle_get_without_ctx(
OekDerivationInfo::for_object(&object, last_v),
)?;
let checksum_mode = checksum_mode(&req);
let checksum_mode = checksum_mode(req);
match (part_number, parse_range_header(req, last_v_meta.size)?) {
(Some(_), Some(_)) => Err(Error::bad_request(
@@ -403,7 +403,7 @@ async fn handle_get_full(
let mut resp_builder = object_headers(
version,
version_meta,
&meta_inner,
meta_inner,
encryption,
checksum_mode,
)
@@ -515,7 +515,7 @@ async fn handle_get_range(
match &version_data {
ObjectVersionData::DeleteMarker => unreachable!(),
ObjectVersionData::Inline(_meta, bytes) => {
let bytes = encryption.decrypt_blob(&bytes)?;
let bytes = encryption.decrypt_blob(bytes)?;
if end as usize <= bytes.len() {
let body = bytes_body(bytes[begin as usize..end as usize].to_vec().into());
Ok(resp_builder.body(body)?)
@@ -564,7 +564,7 @@ async fn handle_get_part(
if part_number != 1 {
return Err(Error::InvalidPart);
}
let bytes = encryption.decrypt_blob(&bytes)?;
let bytes = encryption.decrypt_blob(bytes)?;
assert_eq!(bytes.len() as u64, version_meta.size);
Ok(resp_builder
.header(CONTENT_LENGTH, format!("{}", bytes.len()))
+5 -5
View File
@@ -324,31 +324,31 @@ pub async fn handle_list_parts(
size: s3_xml::IntValue(part.size as i64),
checksum_crc32: match &checksum {
Some(ChecksumValue::Crc32(x)) => {
Some(s3_xml::Value(BASE64_STANDARD.encode(&x)))
Some(s3_xml::Value(BASE64_STANDARD.encode(x)))
}
_ => None,
},
checksum_crc32c: match &checksum {
Some(ChecksumValue::Crc32c(x)) => {
Some(s3_xml::Value(BASE64_STANDARD.encode(&x)))
Some(s3_xml::Value(BASE64_STANDARD.encode(x)))
}
_ => None,
},
checksum_crc64nvme: match &checksum {
Some(ChecksumValue::Crc64Nvme(x)) => {
Some(s3_xml::Value(BASE64_STANDARD.encode(&x)))
Some(s3_xml::Value(BASE64_STANDARD.encode(x)))
}
_ => None,
},
checksum_sha1: match &checksum {
Some(ChecksumValue::Sha1(x)) => {
Some(s3_xml::Value(BASE64_STANDARD.encode(&x)))
Some(s3_xml::Value(BASE64_STANDARD.encode(x)))
}
_ => None,
},
checksum_sha256: match &checksum {
Some(ChecksumValue::Sha256(x)) => {
Some(s3_xml::Value(BASE64_STANDARD.encode(&x)))
Some(s3_xml::Value(BASE64_STANDARD.encode(x)))
}
_ => None,
},
+14 -18
View File
@@ -43,7 +43,7 @@ pub async fn handle_create_multipart_upload(
bucket_name,
..
} = &ctx;
let existing_object = garage.object_table.get(&bucket_id, &key).await?;
let existing_object = garage.object_table.get(bucket_id, key).await?;
let upload_id = gen_uuid();
let timestamp = next_timestamp(existing_object.as_ref());
@@ -57,12 +57,12 @@ pub async fn handle_create_multipart_upload(
// Determine whether object should be encrypted, and if so the key
let encryption = EncryptionParams::new_from_headers(
&garage,
garage,
req.headers(),
OekDerivationInfo {
bucket_id: *bucket_id,
version_id: upload_id,
object_key: &key,
object_key: key,
},
)?;
let object_encryption = encryption.encrypt_meta(meta)?;
@@ -157,12 +157,8 @@ pub async fn handle_put_part(
} => (encryption, checksum_algorithm),
_ => unreachable!(),
};
let (encryption, _) = EncryptionParams::check_decrypt(
&garage,
&req_head.headers,
&object_encryption,
oek_params,
)?;
let (encryption, _) =
EncryptionParams::check_decrypt(garage, &req_head.headers, &object_encryption, oek_params)?;
// Check object is valid and part can be accepted
let first_block = first_block.ok_or_bad_request("Empty body")?;
@@ -459,7 +455,7 @@ pub async fn handle_complete_multipart_upload(
None => object_encryption,
Some(_) => {
let (encryption, meta) = EncryptionParams::check_decrypt(
&garage,
garage,
&req_head.headers,
&object_encryption,
oek_params,
@@ -503,23 +499,23 @@ pub async fn handle_complete_multipart_upload(
key: s3_xml::Value(key),
etag: s3_xml::Value(format!("\"{}\"", etag)),
checksum_crc32: match &checksum_extra {
Some(ChecksumValue::Crc32(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(&x))),
Some(ChecksumValue::Crc32(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(x))),
_ => None,
},
checksum_crc32c: match &checksum_extra {
Some(ChecksumValue::Crc32c(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(&x))),
Some(ChecksumValue::Crc32c(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(x))),
_ => None,
},
checksum_crc64nvme: match &checksum_extra {
Some(ChecksumValue::Crc64Nvme(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(&x))),
Some(ChecksumValue::Crc64Nvme(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(x))),
_ => None,
},
checksum_sha1: match &checksum_extra {
Some(ChecksumValue::Sha1(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(&x))),
Some(ChecksumValue::Sha1(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(x))),
_ => None,
},
checksum_sha256: match &checksum_extra {
Some(ChecksumValue::Sha256(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(&x))),
Some(ChecksumValue::Sha256(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(x))),
_ => None,
},
checksum_type: match checksum_algorithm {
@@ -735,7 +731,7 @@ impl MultipartChecksummer {
part_len: u64,
) -> Result<(), Error> {
self.md5
.update(&hex::decode(&etag).ok_or_message("invalid etag hex")?);
.update(&hex::decode(etag).ok_or_message("invalid etag hex")?);
if let Some(extra) = &mut self.extra {
extra.update(checksum, part_len)?;
}
@@ -815,10 +811,10 @@ impl MultipartExtraChecksummer {
}
},
(Self::CompositeSha1(sha1), Some(ChecksumValue::Sha1(x))) => {
sha1.update(&x);
sha1.update(x);
}
(Self::CompositeSha256(sha256), Some(ChecksumValue::Sha256(x))) => {
sha256.update(&x);
sha256.update(x);
}
_ => {
return Err(Error::internal_error(format!(
+1 -1
View File
@@ -91,7 +91,7 @@ pub async fn handle_put(
OekDerivationInfo {
bucket_id: ctx.bucket_id,
version_id: version_uuid,
object_key: &key,
object_key: key,
},
)?;
+4 -5
View File
@@ -262,7 +262,7 @@ impl DataLayout {
pub(crate) fn primary_block_dir(&self, hash: &Hash) -> PathBuf {
let ipart = self.partition_from(hash);
let idir = self.part_prim[ipart] as usize;
self.block_dir_from(hash, &self.data_dirs[idir].path)
self.block_dir_from(hash, self.data_dirs[idir].path.clone())
}
pub(crate) fn secondary_block_dirs<'a>(
@@ -272,7 +272,7 @@ impl DataLayout {
let ipart = self.partition_from(hash);
self.part_sec[ipart]
.iter()
.map(move |idir| self.block_dir_from(hash, &self.data_dirs[*idir as usize].path))
.map(move |idir| self.block_dir_from(hash, self.data_dirs[*idir as usize].path.clone()))
}
fn partition_from(&self, hash: &Hash) -> usize {
@@ -283,8 +283,7 @@ impl DataLayout {
% DRIVE_NPART
}
fn block_dir_from(&self, hash: &Hash, dir: &PathBuf) -> PathBuf {
let mut path = dir.clone();
fn block_dir_from(&self, hash: &Hash, mut path: PathBuf) -> PathBuf {
path.push(hex::encode(&hash.as_slice()[0..1]));
path.push(hex::encode(&hash.as_slice()[1..2]));
path
@@ -359,7 +358,7 @@ fn make_data_dirs(dirs: &DataDirEnum) -> Result<Vec<DataDir>, Error> {
}
fn dir_not_empty(path: &PathBuf) -> Result<bool, Error> {
for entry in std::fs::read_dir(&path)? {
for entry in std::fs::read_dir(path)? {
let dir = entry?;
let ft = dir.file_type()?;
let name = dir.file_name().into_string().ok();
+1 -1
View File
@@ -89,7 +89,7 @@ impl BlockRc {
.transaction(|tx| {
let mut cnt = 0;
for f in recalc_fns.iter() {
cnt += f(&tx, hash)?;
cnt += f(tx, hash)?;
}
let old_rc = RcEntry::parse_opt(tx.get(&self.rc_table, hash)?);
trace!(
+1 -1
View File
@@ -466,7 +466,7 @@ impl BlockResyncManager {
// First, check whether we are still supposed to store that
// block in the latest cluster layout version.
let storage_nodes = manager.storage_nodes_of(&hash)?;
let storage_nodes = manager.storage_nodes_of(hash)?;
if !storage_nodes.contains(&manager.system.id) {
info!(
+6 -6
View File
@@ -1,6 +1,6 @@
use core::ops::Bound;
use std::path::PathBuf;
use std::path::Path;
use std::sync::Arc;
use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard};
@@ -20,7 +20,7 @@ pub use fjall;
// --
pub(crate) fn open_db(path: &PathBuf, opt: &OpenOpt) -> Result<Db> {
pub(crate) fn open_db(path: &Path, opt: &OpenOpt) -> Result<Db> {
info!("Opening Fjall database at: {}", path.display());
if opt.fsync {
return Err(Error(
@@ -109,11 +109,11 @@ impl IDb for FjallDb {
.keyspace
.list_partitions()
.iter()
.map(|n| decode_name(&n))
.map(|n| decode_name(n))
.collect::<Result<Vec<_>>>()?)
}
fn snapshot(&self, base_path: &PathBuf) -> Result<()> {
fn snapshot(&self, base_path: &Path) -> Result<()> {
std::fs::create_dir_all(base_path)?;
let path = Engine::Fjall.db_path(base_path);
@@ -325,7 +325,7 @@ impl<'a> ITx for FjallTx<'a> {
let high = clone_bound(high);
Ok(Box::new(
self.tx
.range::<Vec<u8>, ByteVecRangeBounds>(&tree, (low, high))
.range::<Vec<u8>, ByteVecRangeBounds>(tree, (low, high))
.map(iterator_remap_tx),
))
}
@@ -340,7 +340,7 @@ impl<'a> ITx for FjallTx<'a> {
let high = clone_bound(high);
Ok(Box::new(
self.tx
.range::<Vec<u8>, ByteVecRangeBounds>(&tree, (low, high))
.range::<Vec<u8>, ByteVecRangeBounds>(tree, (low, high))
.rev()
.map(iterator_remap_tx),
))
+3 -3
View File
@@ -17,7 +17,7 @@ use core::ops::{Bound, RangeBounds};
use std::borrow::Cow;
use std::cell::Cell;
use std::path::PathBuf;
use std::path::Path;
use std::sync::Arc;
use thiserror::Error;
@@ -147,7 +147,7 @@ impl Db {
}
}
pub fn snapshot(&self, path: &PathBuf) -> Result<()> {
pub fn snapshot(&self, path: &Path) -> Result<()> {
self.0.snapshot(path)
}
@@ -348,7 +348,7 @@ pub(crate) trait IDb: Send + Sync {
fn engine(&self) -> String;
fn open_tree(&self, name: &str) -> Result<usize>;
fn list_trees(&self) -> Result<Vec<String>>;
fn snapshot(&self, path: &PathBuf) -> Result<()>;
fn snapshot(&self, path: &Path) -> Result<()>;
fn get(&self, tree: usize, key: &[u8]) -> Result<Option<Value>>;
fn approximate_len(&self, tree: usize) -> Result<usize>;
+5 -5
View File
@@ -3,7 +3,7 @@ use core::ops::Bound;
use std::collections::HashMap;
use std::convert::TryInto;
use std::marker::PhantomPinned;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::sync::{Arc, RwLock};
@@ -22,7 +22,7 @@ pub use heed;
pub(crate) fn open_db(path: &PathBuf, opt: &OpenOpt) -> Result<Db> {
info!("Opening LMDB database at: {}", path.display());
if let Err(e) = std::fs::create_dir_all(&path) {
if let Err(e) = std::fs::create_dir_all(path) {
return Err(Error(
format!("Unable to create LMDB data directory: {}", e).into(),
));
@@ -44,7 +44,7 @@ pub(crate) fn open_db(path: &PathBuf, opt: &OpenOpt) -> Result<Db> {
env_builder.flag(heed::flags::Flags::MdbNoSync);
}
}
match env_builder.open(&path) {
match env_builder.open(path) {
Err(heed::Error::Io(e)) if e.kind() == std::io::ErrorKind::OutOfMemory => {
return Err(Error(
"OutOfMemory error while trying to open LMDB database. This can happen \
@@ -147,7 +147,7 @@ impl IDb for LmdbDb {
Ok(ret2)
}
fn snapshot(&self, base_path: &PathBuf) -> Result<()> {
fn snapshot(&self, base_path: &Path) -> Result<()> {
std::fs::create_dir_all(base_path)?;
let path = Engine::Lmdb.db_path(base_path);
self.db
@@ -399,7 +399,7 @@ where
// before the tx it is pointing to.
unsafe { &*&raw const *tx }
};
let iter = iterfun(&tx_lifetime_overextended)?;
let iter = iterfun(tx_lifetime_overextended)?;
*boxed.as_mut().iter() = Some(iter);
+3 -3
View File
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use crate::{Db, Error, Result};
@@ -25,8 +25,8 @@ impl Engine {
}
/// Return engine-specific DB path from base path
pub fn db_path(&self, base_path: &PathBuf) -> PathBuf {
let mut ret = base_path.clone();
pub fn db_path(&self, base_path: &Path) -> PathBuf {
let mut ret = base_path.to_path_buf();
match self {
Self::Lmdb => {
ret.push("db.lmdb");
+4 -4
View File
@@ -1,7 +1,7 @@
use core::ops::Bound;
use std::marker::PhantomPinned;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::ptr::NonNull;
use std::sync::{Arc, Mutex, RwLock};
@@ -110,7 +110,7 @@ impl IDb for SqliteDb {
let name = format!("tree_{}", name.replace(':', "_COLON_"));
let mut trees = self.trees.write().unwrap();
if let Some(i) = trees.iter().position(|x| x.as_ref() == &name) {
if let Some(i) = trees.iter().position(|x| x.as_ref() == name) {
Ok(i)
} else {
let db = self.db.get()?;
@@ -150,10 +150,10 @@ impl IDb for SqliteDb {
Ok(trees)
}
fn snapshot(&self, base_path: &PathBuf) -> Result<()> {
fn snapshot(&self, base_path: &Path) -> Result<()> {
std::fs::create_dir_all(base_path)?;
let path = Engine::Sqlite
.db_path(&base_path)
.db_path(base_path)
.into_os_string()
.into_string()
.map_err(|_| Error("invalid sqlite path string".into()))?;
+2 -2
View File
@@ -73,7 +73,7 @@ impl Cli {
let mut actions = vec![];
for node in opt.replace.iter() {
let id = find_matching_node(&status, &layout, &node)?;
let id = find_matching_node(&status, &layout, node)?;
actions.push(NodeRoleChange {
id,
@@ -82,7 +82,7 @@ impl Cli {
}
for node in opt.node_ids.iter() {
let id = find_matching_node(&status, &layout, &node)?;
let id = find_matching_node(&status, &layout, node)?;
let current = get_staged_or_current_role(&id, &layout);
+1 -1
View File
@@ -168,7 +168,7 @@ pub fn table_list_abbr<T: IntoIterator<Item = S>, S: AsRef<str>>(values: T) -> S
pub fn parse_expires_in(expires_in: &Option<String>) -> Result<Option<DateTime<Utc>>, Error> {
expires_in
.as_ref()
.map(|x| parse_duration::parse::parse(&x).map(|dur| Utc::now() + dur))
.map(|x| parse_duration::parse::parse(x).map(|dur| Utc::now() + dur))
.transpose()
.ok_or_message("Invalid duration passed for --expires-in parameter")
}
+1 -1
View File
@@ -110,7 +110,7 @@ pub async fn run_server(config_file: PathBuf, secrets: Secrets) -> Result<(), Er
if let Some(web_config) = &config.s3_web {
info!("Initializing web server...");
let web_server = WebServer::new(garage.clone(), &web_config);
let web_server = WebServer::new(garage.clone(), web_config);
servers.push((
"Web",
tokio::spawn(web_server.run(web_config.bind_addr.clone(), watch_cancel.clone())),
+5 -5
View File
@@ -244,7 +244,7 @@ impl<'a> RequestBuilder<'a> {
);
all_headers.insert(
HeaderName::from_static("x-amz-trailer"),
HeaderValue::from_str(&trailer_algorithm).unwrap(),
HeaderValue::from_str(trailer_algorithm).unwrap(),
);
all_headers.insert(
@@ -252,8 +252,8 @@ impl<'a> RequestBuilder<'a> {
to_streaming_unsigned_trailer_body(
&self.body,
*chunk_size,
&trailer_algorithm,
&trailer_value,
trailer_algorithm,
trailer_value,
)
.len()
.to_string()
@@ -330,8 +330,8 @@ impl<'a> RequestBuilder<'a> {
} => to_streaming_unsigned_trailer_body(
&self.body,
*chunk_size,
&trailer_algorithm,
&trailer_value,
trailer_algorithm,
trailer_value,
),
_ => self.body.clone(),
};
+1 -1
View File
@@ -371,7 +371,7 @@ impl K2vClient {
use sha2::{Digest, Sha256};
let mut hasher = Sha256::new();
hasher.update(req.body());
let hash = hex::encode(&hasher.finalize());
let hash = hex::encode(hasher.finalize());
req.headers_mut()
.insert(AMZ_CONTENT_SHA256, hash.try_into().unwrap());
+2 -2
View File
@@ -95,7 +95,7 @@ impl<'a> BucketHelper<'a> {
if let Some(Some(bucket_id)) = api_key_params.local_aliases.get(bucket_name) {
self.0
.bucket_table
.get_local(&EmptyKey, &bucket_id)?
.get_local(&EmptyKey, bucket_id)?
.filter(|x| !x.state.is_deleted())
} else {
self.resolve_global_bucket_fast(bucket_name)?
@@ -157,7 +157,7 @@ impl<'a> BucketHelper<'a> {
let local_alias = self
.0
.key_table
.get(&EmptyKey, &key_id)
.get(&EmptyKey, key_id)
.await?
.and_then(|k| k.state.into_option())
.ok_or_else(|| GarageError::Message(format!("access key {} has been deleted", key_id)))?
+1 -1
View File
@@ -159,7 +159,7 @@ impl Key {
return Err("The specified key ID is not a valid Garage key ID (starts with `GK`, followed by 12 hex-encoded bytes)");
}
if secret_key.len() != 64 || hex::decode(&secret_key).is_err() {
if secret_key.len() != 64 || hex::decode(secret_key).is_err() {
return Err("The specified secret key is not a valid Garage secret key (composed of 32 hex-encoded bytes)");
}
+3 -3
View File
@@ -1,5 +1,5 @@
use std::fs;
use std::path::PathBuf;
use std::path::Path;
use std::sync::Arc;
use std::sync::Mutex;
use std::time::{Duration, Instant};
@@ -67,9 +67,9 @@ pub fn snapshot_metadata(garage: &Garage) -> Result<(), Error> {
Ok(())
}
fn cleanup_snapshots(snapshots_dir: &PathBuf) -> Result<(), Error> {
fn cleanup_snapshots(snapshots_dir: &Path) -> Result<(), Error> {
let mut snapshots =
fs::read_dir(&snapshots_dir)?.collect::<Result<Vec<fs::DirEntry>, std::io::Error>>()?;
fs::read_dir(snapshots_dir)?.collect::<Result<Vec<fs::DirEntry>, std::io::Error>>()?;
snapshots.retain(|x| x.file_name().len() > 8);
snapshots.sort_by_key(|x| x.file_name());
+1 -1
View File
@@ -113,7 +113,7 @@ impl ConsulDiscovery {
let mut headers = reqwest::header::HeaderMap::new();
headers.insert(
"x-consul-token",
reqwest::header::HeaderValue::from_str(&token)?,
reqwest::header::HeaderValue::from_str(token)?,
);
builder = builder.default_headers(headers);
}
+2 -2
View File
@@ -35,8 +35,8 @@ fn check_against_naive(cl: &LayoutVersion) -> Result<bool, Error> {
zone_token.insert(z.clone(), 0);
}
for uuid in cl.nongateway_nodes() {
let z = cl.expect_get_node_zone(&uuid);
let c = cl.expect_get_node_capacity(&uuid);
let z = cl.expect_get_node_zone(uuid);
let c = cl.expect_get_node_capacity(uuid);
zone_token.insert(
z.to_string(),
zone_token[z] + min(NB_PARTITIONS, (c / over_size) as usize),
+1 -1
View File
@@ -592,7 +592,7 @@ impl RpcHelper {
for i in 0..current_layout.replication_factor {
for vn in vernodes.iter() {
if let Some(n) = vn.get(i) {
if !nodes.contains(&n) {
if !nodes.contains(n) {
if *n == self.0.our_node_id {
// it's always fast (almost free) to ask locally,
// so always put that as first choice
+6 -6
View File
@@ -429,11 +429,11 @@ async fn handle_inner(
// - Caching directives such as If-None-Match, etc, which are not relevant
let cleaned_req = Request::builder().uri(req.uri()).body(()).unwrap();
let mut ret = match req.method() {
&Method::HEAD => {
let mut ret = match *req.method() {
Method::HEAD => {
handle_head_without_ctx(garage, &cleaned_req, bucket_id, key, None).await?
}
&Method::GET => {
Method::GET => {
handle_get_without_ctx(
garage,
&cleaned_req,
@@ -451,9 +451,9 @@ async fn handle_inner(
Ok(ret)
} else {
match req.method() {
&Method::HEAD => handle_head_without_ctx(garage, req, bucket_id, key, None).await,
&Method::GET => {
match *req.method() {
Method::HEAD => handle_head_without_ctx(garage, req, bucket_id, key, None).await,
Method::GET => {
handle_get_without_ctx(garage, req, bucket_id, key, None, Default::default()).await
}
_ => Err(ApiError::bad_request("HTTP method not supported")),