diff --git a/src/api/admin/admin_token.rs b/src/api/admin/admin_token.rs index 0f9c66d2..242c9958 100644 --- a/src/api/admin/admin_token.rs +++ b/src/api/admin/admin_token.rs @@ -143,7 +143,7 @@ impl RequestHandler for UpdateAdminTokenRequest { garage: &Arc, _admin: &Admin, ) -> Result { - 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, _admin: &Admin, ) -> Result { - 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, diff --git a/src/api/admin/api_server.rs b/src/api/admin/api_server.rs index 19a88024..aa8d8e96 100644 --- a/src/api/admin/api_server.rs +++ b/src/api/admin/api_server.rs @@ -64,7 +64,7 @@ impl EndpointHandler 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 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("*")); diff --git a/src/api/admin/block.rs b/src/api/admin/block.rs index 586f8554..30729866 100644 --- a/src/api/admin/block.rs +++ b/src/api/admin/block.rs @@ -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, prefix: &str) -> Result>() }) .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, }) diff --git a/src/api/admin/layout.rs b/src/api/admin/layout.rs index b0b652e6..7f9f5412 100644 --- a/src/api/admin/layout.rs +++ b/src/api/admin/layout.rs @@ -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), diff --git a/src/api/common/signature/checksum.rs b/src/api/common/signature/checksum.rs index d223175f..09eae74c 100644 --- a/src/api/common/signature/checksum.rs +++ b/src/api/common/signature/checksum.rs @@ -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 => (), } diff --git a/src/api/common/signature/mod.rs b/src/api/common/signature/mod.rs index 6f1748c3..bae63d1b 100644 --- a/src/api/common/signature/mod.rs +++ b/src/api/common/signature/mod.rs @@ -69,7 +69,7 @@ pub fn verify_request( mut req: Request, service: &'static str, ) -> Result { - 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, diff --git a/src/api/common/signature/payload.rs b/src/api/common/signature/payload.rs index 0c657601..d320835c 100644 --- a/src/api/common/signature/payload.rs +++ b/src/api/common/signature/payload.rs @@ -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("&") diff --git a/src/api/k2v/index.rs b/src/api/k2v/index.rs index f4beba24..5188c32f 100644 --- a/src/api/k2v/index.rs +++ b/src/api/k2v/index.rs @@ -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, diff --git a/src/api/s3/bucket.rs b/src/api/s3/bucket.rs index 217d74f0..b84a06bb 100644 --- a/src/api/s3/bucket.rs +++ b/src/api/s3/bucket.rs @@ -57,23 +57,23 @@ pub fn handle_get_bucket_acl(ctx: ReqCtx) -> Result, 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()), }); } diff --git a/src/api/s3/encryption.rs b/src/api/s3/encryption.rs index c02e126c..0c404e27 100644 --- a/src/api/s3/encryption.rs +++ b/src/api/s3/encryption.rs @@ -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; } diff --git a/src/api/s3/get.rs b/src/api/s3/get.rs index b6a1aacc..bf2e68c7 100644 --- a/src/api/s3/get.rs +++ b/src/api/s3/get.rs @@ -124,7 +124,7 @@ fn handle_http_precondition( ) -> Result>, 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())) diff --git a/src/api/s3/list.rs b/src/api/s3/list.rs index c62cf118..0d19fda6 100644 --- a/src/api/s3/list.rs +++ b/src/api/s3/list.rs @@ -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, }, diff --git a/src/api/s3/multipart.rs b/src/api/s3/multipart.rs index 57ed22e9..fb246041 100644 --- a/src/api/s3/multipart.rs +++ b/src/api/s3/multipart.rs @@ -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!( diff --git a/src/api/s3/put.rs b/src/api/s3/put.rs index 7a9c4a62..bac5a678 100644 --- a/src/api/s3/put.rs +++ b/src/api/s3/put.rs @@ -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, }, )?; diff --git a/src/block/layout.rs b/src/block/layout.rs index 00e3debb..ae57a1cc 100644 --- a/src/block/layout.rs +++ b/src/block/layout.rs @@ -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, Error> { } fn dir_not_empty(path: &PathBuf) -> Result { - 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(); diff --git a/src/block/rc.rs b/src/block/rc.rs index 4a55ee29..d8b611ed 100644 --- a/src/block/rc.rs +++ b/src/block/rc.rs @@ -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!( diff --git a/src/block/resync.rs b/src/block/resync.rs index f60b540f..28666a71 100644 --- a/src/block/resync.rs +++ b/src/block/resync.rs @@ -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!( diff --git a/src/db/fjall_adapter.rs b/src/db/fjall_adapter.rs index ecdece4b..d1e4f8ac 100644 --- a/src/db/fjall_adapter.rs +++ b/src/db/fjall_adapter.rs @@ -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 { +pub(crate) fn open_db(path: &Path, opt: &OpenOpt) -> Result { 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::>>()?) } - 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::, ByteVecRangeBounds>(&tree, (low, high)) + .range::, 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::, ByteVecRangeBounds>(&tree, (low, high)) + .range::, ByteVecRangeBounds>(tree, (low, high)) .rev() .map(iterator_remap_tx), )) diff --git a/src/db/lib.rs b/src/db/lib.rs index 42f49b6f..3e83e0f0 100644 --- a/src/db/lib.rs +++ b/src/db/lib.rs @@ -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; fn list_trees(&self) -> Result>; - fn snapshot(&self, path: &PathBuf) -> Result<()>; + fn snapshot(&self, path: &Path) -> Result<()>; fn get(&self, tree: usize, key: &[u8]) -> Result>; fn approximate_len(&self, tree: usize) -> Result; diff --git a/src/db/lmdb_adapter.rs b/src/db/lmdb_adapter.rs index ac185ae9..83bd0008 100644 --- a/src/db/lmdb_adapter.rs +++ b/src/db/lmdb_adapter.rs @@ -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 { 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 { 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); diff --git a/src/db/open.rs b/src/db/open.rs index 23391c61..264550d7 100644 --- a/src/db/open.rs +++ b/src/db/open.rs @@ -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"); diff --git a/src/db/sqlite_adapter.rs b/src/db/sqlite_adapter.rs index a03ee8ef..5c052501 100644 --- a/src/db/sqlite_adapter.rs +++ b/src/db/sqlite_adapter.rs @@ -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()))?; diff --git a/src/garage/cli/remote/layout.rs b/src/garage/cli/remote/layout.rs index 1872f63e..edf92efc 100644 --- a/src/garage/cli/remote/layout.rs +++ b/src/garage/cli/remote/layout.rs @@ -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); diff --git a/src/garage/cli/remote/mod.rs b/src/garage/cli/remote/mod.rs index 31cbdc6e..d1a20989 100644 --- a/src/garage/cli/remote/mod.rs +++ b/src/garage/cli/remote/mod.rs @@ -168,7 +168,7 @@ pub fn table_list_abbr, S: AsRef>(values: T) -> S pub fn parse_expires_in(expires_in: &Option) -> Result>, 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") } diff --git a/src/garage/server.rs b/src/garage/server.rs index a723a2f7..d0aeb314 100644 --- a/src/garage/server.rs +++ b/src/garage/server.rs @@ -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())), diff --git a/src/garage/tests/common/custom_requester.rs b/src/garage/tests/common/custom_requester.rs index 6a8eed38..ee78ad2d 100644 --- a/src/garage/tests/common/custom_requester.rs +++ b/src/garage/tests/common/custom_requester.rs @@ -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(), }; diff --git a/src/k2v-client/lib.rs b/src/k2v-client/lib.rs index a5485cf9..addcb2c0 100644 --- a/src/k2v-client/lib.rs +++ b/src/k2v-client/lib.rs @@ -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()); diff --git a/src/model/helper/bucket.rs b/src/model/helper/bucket.rs index c82dd683..aab13bac 100644 --- a/src/model/helper/bucket.rs +++ b/src/model/helper/bucket.rs @@ -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)))? diff --git a/src/model/key_table.rs b/src/model/key_table.rs index 6cf0800b..ded9832d 100644 --- a/src/model/key_table.rs +++ b/src/model/key_table.rs @@ -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)"); } diff --git a/src/model/snapshot.rs b/src/model/snapshot.rs index 8e8995f9..d66e7935 100644 --- a/src/model/snapshot.rs +++ b/src/model/snapshot.rs @@ -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::, std::io::Error>>()?; + fs::read_dir(snapshots_dir)?.collect::, std::io::Error>>()?; snapshots.retain(|x| x.file_name().len() > 8); snapshots.sort_by_key(|x| x.file_name()); diff --git a/src/rpc/consul.rs b/src/rpc/consul.rs index f16a323e..9391e220 100644 --- a/src/rpc/consul.rs +++ b/src/rpc/consul.rs @@ -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); } diff --git a/src/rpc/layout/test.rs b/src/rpc/layout/test.rs index 2d29914e..ab191252 100644 --- a/src/rpc/layout/test.rs +++ b/src/rpc/layout/test.rs @@ -35,8 +35,8 @@ fn check_against_naive(cl: &LayoutVersion) -> Result { 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), diff --git a/src/rpc/rpc_helper.rs b/src/rpc/rpc_helper.rs index 78359762..9c8c90ff 100644 --- a/src/rpc/rpc_helper.rs +++ b/src/rpc/rpc_helper.rs @@ -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 diff --git a/src/web/web_server.rs b/src/web/web_server.rs index dffd84d9..46ef40f3 100644 --- a/src/web/web_server.rs +++ b/src/web/web_server.rs @@ -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")),