More clippy fixes

This commit is contained in:
Alex 2023-01-26 17:26:32 +01:00
parent 3113f6b5f2
commit 8e93d69974
14 changed files with 29 additions and 27 deletions

View file

@ -103,7 +103,7 @@ impl AdminApiServer {
.bucket_helper()
.resolve_global_bucket_name(&domain_string)
.await?
.ok_or_else(|| HelperError::NoSuchBucket(domain_string))?;
.ok_or(HelperError::NoSuchBucket(domain_string))?;
let bucket = self
.garage

View file

@ -167,7 +167,7 @@ async fn bucket_info_results(
let quotas = state.quotas.get();
let res =
GetBucketInfoResult {
id: hex::encode(&bucket.id),
id: hex::encode(bucket.id),
global_aliases: state
.aliases
.items()
@ -575,6 +575,6 @@ pub async fn handle_local_unalias_bucket(
// ---- HELPER ----
fn parse_bucket_id(id: &str) -> Result<Uuid, Error> {
let id_hex = hex::decode(&id).ok_or_bad_request("Invalid bucket id")?;
let id_hex = hex::decode(id).ok_or_bad_request("Invalid bucket id")?;
Ok(Uuid::try_from(&id_hex).ok_or_bad_request("Invalid bucket id")?)
}

View file

@ -305,7 +305,7 @@ fn parse_create_bucket_xml(xml_bytes: &[u8]) -> Option<Option<String>> {
let mut ret = None;
for item in cbc.children() {
if item.has_tag_name("LocationConstraint") {
if ret != None {
if ret.is_some() {
return None;
}
ret = Some(item.text()?.to_string());

View file

@ -140,7 +140,7 @@ pub async fn handle_post_object(
.await?;
let decoded_policy = BASE64_STANDARD
.decode(&policy)
.decode(policy)
.ok_or_bad_request("Invalid policy")?;
let decoded_policy: Policy =
serde_json::from_slice(&decoded_policy).ok_or_bad_request("Invalid policy")?;

View file

@ -38,7 +38,7 @@ impl BlockManagerMetrics {
.u64_value_observer("block.compression_level", move |observer| {
match compression_level {
Some(v) => observer.observe(v as u64, &[]),
None => observer.observe(0 as u64, &[]),
None => observer.observe(0_u64, &[]),
}
})
.with_description("Garage compression level for node")

View file

@ -24,9 +24,9 @@ impl BlockRc {
tx: &mut db::Transaction,
hash: &Hash,
) -> db::TxOpResult<bool> {
let old_rc = RcEntry::parse_opt(tx.get(&self.rc, &hash)?);
let old_rc = RcEntry::parse_opt(tx.get(&self.rc, hash)?);
match old_rc.increment().serialize() {
Some(x) => tx.insert(&self.rc, &hash, x)?,
Some(x) => tx.insert(&self.rc, hash, x)?,
None => unreachable!(),
};
Ok(old_rc.is_zero())
@ -39,10 +39,10 @@ impl BlockRc {
tx: &mut db::Transaction,
hash: &Hash,
) -> db::TxOpResult<bool> {
let new_rc = RcEntry::parse_opt(tx.get(&self.rc, &hash)?).decrement();
let new_rc = RcEntry::parse_opt(tx.get(&self.rc, hash)?).decrement();
match new_rc.serialize() {
Some(x) => tx.insert(&self.rc, &hash, x)?,
None => tx.remove(&self.rc, &hash)?,
Some(x) => tx.insert(&self.rc, hash, x)?,
None => tx.remove(&self.rc, hash)?,
};
Ok(matches!(new_rc, RcEntry::Deletable { .. }))
}
@ -57,10 +57,10 @@ impl BlockRc {
pub(crate) fn clear_deleted_block_rc(&self, hash: &Hash) -> Result<(), Error> {
let now = now_msec();
self.rc.db().transaction(|mut tx| {
let rcval = RcEntry::parse_opt(tx.get(&self.rc, &hash)?);
let rcval = RcEntry::parse_opt(tx.get(&self.rc, hash)?);
match rcval {
RcEntry::Deletable { at_time } if now > at_time => {
tx.remove(&self.rc, &hash)?;
tx.remove(&self.rc, hash)?;
}
_ => (),
};

View file

@ -466,11 +466,11 @@ impl BlockStoreIterator {
let ent_type = data_dir_ent.file_type().await?;
let name = name.strip_suffix(".zst").unwrap_or(&name);
if name.len() == 2 && hex::decode(&name).is_ok() && ent_type.is_dir() {
if name.len() == 2 && hex::decode(name).is_ok() && ent_type.is_dir() {
let path = data_dir_ent.path();
self.path.push(ReadingDir::Pending(path));
} else if name.len() == 64 {
if let Ok(h) = hex::decode(&name) {
if let Ok(h) = hex::decode(name) {
let mut hash = [0u8; 32];
hash.copy_from_slice(&h);
return Ok(Some(hash.into()));

View file

@ -159,7 +159,7 @@ impl Garage {
};
let network_key = NetworkKey::from_slice(
&hex::decode(&config.rpc_secret.as_ref().unwrap()).expect("Invalid RPC secret key")[..],
&hex::decode(config.rpc_secret.as_ref().unwrap()).expect("Invalid RPC secret key")[..],
)
.expect("Invalid RPC secret key");

View file

@ -269,6 +269,7 @@ impl CountedItem for K2VItem {
&self.partition.partition_key
}
#[allow(clippy::bool_to_int_with_if)]
fn counts(&self) -> Vec<(&'static str, i64)> {
let values = self.values();
@ -313,7 +314,7 @@ mod tests {
values: vec![(6, DvvsValue::Value(vec![16])), (7, DvvsValue::Deleted)],
};
let mut e3 = e1.clone();
let mut e3 = e1;
e3.merge(&e2);
assert_eq!(e2, e3);
}

View file

@ -37,7 +37,7 @@ use crate::k2v::sub::*;
const POLL_RANGE_EXTRA_DELAY: Duration = Duration::from_millis(200);
const TIMESTAMP_KEY: &'static [u8] = b"timestamp";
const TIMESTAMP_KEY: &[u8] = b"timestamp";
/// RPC messages for K2V
#[derive(Debug, Serialize, Deserialize)]
@ -418,7 +418,7 @@ impl K2VRpcHandler {
.data
.update_entry_with(&item.partition, &item.sort_key, |tx, ent| {
let old_local_timestamp = tx
.get(&local_timestamp_tree, TIMESTAMP_KEY)?
.get(local_timestamp_tree, TIMESTAMP_KEY)?
.and_then(|x| x.try_into().ok())
.map(u64::from_be_bytes)
.unwrap_or_default();
@ -438,7 +438,7 @@ impl K2VRpcHandler {
);
tx.insert(
&local_timestamp_tree,
local_timestamp_tree,
TIMESTAMP_KEY,
u64::to_be_bytes(new_local_timestamp),
)?;

View file

@ -63,7 +63,7 @@ impl RangeSeenMarker {
None => {
self.items.insert(item.sort_key.clone(), cc.vector_clock);
}
Some(ent) => *ent = vclock_max(&ent, &cc.vector_clock),
Some(ent) => *ent = vclock_max(ent, &cc.vector_clock),
}
}
}
@ -71,7 +71,7 @@ impl RangeSeenMarker {
pub fn canonicalize(&mut self) {
let self_vc = &self.vector_clock;
self.items.retain(|_sk, vc| vclock_gt(&vc, self_vc))
self.items.retain(|_sk, vc| vclock_gt(vc, self_vc))
}
pub fn encode(&mut self) -> Result<String, Error> {
@ -84,7 +84,7 @@ impl RangeSeenMarker {
/// Decode from msgpack+zstd+b64 representation, returns None on error.
pub fn decode(s: &str) -> Option<Self> {
let bytes = BASE64_STANDARD.decode(&s).ok()?;
let bytes = BASE64_STANDARD.decode(s).ok()?;
let bytes = zstd::stream::decode_all(&mut &bytes[..]).ok()?;
nonversioned_decode(&bytes).ok()
}
@ -99,7 +99,7 @@ impl RangeSeenMarker {
&& self
.items
.get(&item.sort_key)
.map(|vc| vclock_gt(&cc.vector_clock, &vc))
.map(|vc| vclock_gt(&cc.vector_clock, vc))
.unwrap_or(true)
}
}

View file

@ -355,6 +355,7 @@ impl CountedItem for Object {
fn counts(&self) -> Vec<(&'static str, i64)> {
let versions = self.versions();
#[allow(clippy::bool_to_int_with_if)]
let n_objects = if versions.iter().any(|v| v.is_data()) {
1
} else {

View file

@ -113,7 +113,7 @@ impl ConsulDiscovery {
let pubkey = ent
.node_meta
.get("pubkey")
.and_then(|k| hex::decode(&k).ok())
.and_then(|k| hex::decode(k).ok())
.and_then(|k| NodeID::from_slice(&k[..]));
if let (Some(ip), Some(pubkey)) = (ip, pubkey) {
ret.push((pubkey, SocketAddr::new(ip, ent.service_port)));

View file

@ -215,7 +215,7 @@ pub fn gen_node_key(metadata_dir: &Path) -> Result<NodeKey, Error> {
} else {
if !metadata_dir.exists() {
info!("Metadata directory does not exist, creating it.");
std::fs::create_dir(&metadata_dir)?;
std::fs::create_dir(metadata_dir)?;
}
info!("Generating new node key pair.");
@ -419,7 +419,7 @@ impl System {
.get(&n.id.into())
.cloned()
.map(|(_, st)| st)
.unwrap_or(NodeStatus::unknown()),
.unwrap_or_else(NodeStatus::unknown),
})
.collect::<Vec<_>>();
known_nodes