Skip to content

Commit

Permalink
clippy-1.70.0 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Dec 25, 2023
1 parent 9f90a75 commit 2eccd07
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 48 deletions.
13 changes: 6 additions & 7 deletions taskchampion/taskchampion/src/server/cloud/gcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,17 @@ impl Service for GcpService {
object: name.clone(),
..Default::default()
}));
let generation;
if is_http_error(404, &get_res) {
let generation = if is_http_error(404, &get_res) {
// If a value was expected, that expectation has not been met.
if existing_value.is_some() {
return Ok(false);
}
// Generation 0 indicates that the upload should succeed only if the object does not
// exist.
generation = 0;
0
} else {
generation = get_res?.generation;
}
get_res?.generation
};

// If the file existed, then verify its contents.
if generation > 0 {
Expand Down Expand Up @@ -197,7 +196,7 @@ impl<'a> Iterator for ObjectIterator<'a> {
// If the iterator is just starting, fetch the first response.
if self.last_response.is_none() {
if let Err(e) = self.fetch_batch() {
return Some(Err(e.into()));
return Some(Err(e));
}
}
if let Some(ref result) = self.last_response {
Expand All @@ -215,7 +214,7 @@ impl<'a> Iterator for ObjectIterator<'a> {
} else if result.next_page_token.is_some() {
// Fetch the next page and try again.
if let Err(e) = self.fetch_batch() {
return Some(Err(e.into()));
return Some(Err(e));
}
return self.next();
}
Expand Down
57 changes: 22 additions & 35 deletions taskchampion/taskchampion/src/server/cloud/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl<SVC: Service> CloudServer<SVC> {
/// Get the possible child versions of the given parent version, based only on the object
/// names.
fn get_child_versions(&mut self, parent_version_id: &VersionId) -> Result<Vec<VersionId>> {
Ok(self
self
.service
.list(format!("v-{}-", parent_version_id.as_simple()).as_bytes())
.filter_map(|res| match res {
Expand All @@ -170,7 +170,7 @@ impl<SVC: Service> CloudServer<SVC> {
}
Err(e) => Some(Err(e)),
})
.collect::<Result<Vec<_>>>()?)
.collect::<Result<Vec<_>>>()
}

/// Determine the snapshot urgency. This is done probabalistically, so that approximately one
Expand Down Expand Up @@ -230,18 +230,13 @@ impl<SVC: Service> CloudServer<SVC> {
let mut iterations = versions.len() + 1; // For cycle detection.
let latest = self.get_latest()?;
if let Some(mut c) = latest {
loop {
match parent_of(c) {
Some(p) => {
fwd_chain.insert(p, c);
rev_chain.insert(c, p);
c = p;
iterations -= 1;
if iterations == 0 {
return Err(Error::Server("Version cycle detected".into()));
}
}
None => break,
while let Some(p) = parent_of(c) {
fwd_chain.insert(p, c);
rev_chain.insert(c, p);
c = p;
iterations -= 1;
if iterations == 0 {
return Err(Error::Server("Version cycle detected".into()));
}
}
}
Expand Down Expand Up @@ -286,11 +281,7 @@ impl<SVC: Service> CloudServer<SVC> {
.list(b"s-")
.filter_map(|res| match res {
Ok(ObjectInfo { name, .. }) => {
if let Some(v) = Self::parse_snapshot_name(&name) {
Some(Ok(v))
} else {
None
}
Self::parse_snapshot_name(&name).map(Ok)
}
Err(e) => Some(Err(e)),
})
Expand Down Expand Up @@ -327,15 +318,11 @@ impl<SVC: Service> CloudServer<SVC> {
// Now continue iterating backward from that version; any version in `old_versions` can be
// deleted.
let mut version = latest_snapshot;
loop {
if let Some(parent) = rev_chain.get(&version) {
if old_versions.contains(&version) {
self.service.del(&Self::version_name(parent, &version))?;
}
version = *parent;
} else {
break;
while let Some(parent) = rev_chain.get(&version) {
if old_versions.contains(&version) {
self.service.del(&Self::version_name(parent, &version))?;
}
version = *parent;
}

Ok(())
Expand Down Expand Up @@ -363,7 +350,7 @@ impl<SVC: Service> Server for CloudServer<SVC> {
let new_name = Self::version_name(&parent_version_id, &version_id);
let sealed = self.cryptor.seal(Unsealed {
version_id,
payload: history_segment.into(),
payload: history_segment,
})?;
self.service.put(&new_name, sealed.as_ref())?;

Expand All @@ -373,7 +360,7 @@ impl<SVC: Service> Server for CloudServer<SVC> {
}

// Try to compare-and-swap this value into LATEST
let old_value = latest.map(|l| version_to_bytes(l));
let old_value = latest.map(version_to_bytes);
let new_value = version_to_bytes(version_id);
if !self
.service
Expand All @@ -392,7 +379,7 @@ impl<SVC: Service> Server for CloudServer<SVC> {
// Attempt a cleanup, but ignore errors.
let _ = self.maybe_cleanup();

return Ok((AddVersionResult::Ok(version_id), self.snapshot_urgency()?));
Ok((AddVersionResult::Ok(version_id), self.snapshot_urgency()?))
}

fn get_child_version(&mut self, parent_version_id: VersionId) -> Result<GetVersionResult> {
Expand All @@ -417,7 +404,7 @@ impl<SVC: Service> Server for CloudServer<SVC> {
}
if true_child.is_none() {
for child in children {
if self.get_child_versions(&child)?.len() > 0 {
if !self.get_child_versions(child)?.is_empty() {
true_child = Some(*child)
}
}
Expand Down Expand Up @@ -452,15 +439,15 @@ impl<SVC: Service> Server for CloudServer<SVC> {
let name = Self::snapshot_name(&version_id);
let sealed = self.cryptor.seal(Unsealed {
version_id,
payload: snapshot.into(),
payload: snapshot,
})?;
self.service.put(&name, sealed.as_ref())?;
Ok(())
}

fn get_snapshot(&mut self) -> Result<Option<(VersionId, Snapshot)>> {
// Pick the first snapshot we find.
let Some(name) = self.service.list(b"s-").nth(0) else {
let Some(name) = self.service.list(b"s-").next() else {
return Ok(None);
};
let ObjectInfo { name, .. } = name?;
Expand All @@ -472,7 +459,7 @@ impl<SVC: Service> Server for CloudServer<SVC> {
};
let unsealed = self.cryptor.unseal(Sealed {
version_id,
payload: payload.into(),
payload,
})?;
Ok(Some((version_id, unsealed.payload)))
}
Expand Down Expand Up @@ -853,7 +840,7 @@ mod tests {
server.mock_add_version(v2, V3, 1000, b"second");
server.mock_set_latest(v2);
server.add_version_intercept = Some(|service| {
service.put(&LATEST, &version_to_bytes(V3)).unwrap();
service.put(LATEST, &version_to_bytes(V3)).unwrap();
});
let (res, _) = server.add_version(v2, b"history".to_vec()).unwrap();
assert_eq!(res, AddVersionResult::ExpectedParentVersion(V3));
Expand Down
12 changes: 6 additions & 6 deletions taskchampion/taskchampion/src/server/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ pub(super) struct Unsealed {
pub(super) payload: Vec<u8>,
}

impl Into<Vec<u8>> for Unsealed {
fn into(self) -> Vec<u8> {
self.payload
impl From<Unsealed> for Vec<u8> {
fn from(val: Unsealed) -> Self {
val.payload
}
}

Expand All @@ -188,9 +188,9 @@ impl AsRef<[u8]> for Sealed {
}
}

impl Into<Vec<u8>> for Sealed {
fn into(self) -> Vec<u8> {
self.payload
impl From<Sealed> for Vec<u8> {
fn from(val: Sealed) -> Self {
val.payload
}
}

Expand Down

0 comments on commit 2eccd07

Please sign in to comment.