Skip to content

Commit

Permalink
Add clippy CI
Browse files Browse the repository at this point in the history
  • Loading branch information
lbirkert committed Aug 20, 2024
1 parent 3109a0a commit 6f7a87d
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 55 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Lint code

on:
push:
branches:
- main
pull_request:

concurrency:
group: "pages"
cancel-in-progress: true

jobs:
clippy:
name: Check for clippy warnings
runs-on: ubuntu-latest
env:
RUSTGLAGS: '-D warnings'
steps:
- uses: actions/checkout@v4
- run: rustup update stable && rustup default stable
- run: cargo clippy --verbose
4 changes: 2 additions & 2 deletions .github/workflows/sites.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- main
paths:
- 'sites/quixbyte.org/**'
- 'sites/*/**'

concurrency:
group: "pages"
Expand All @@ -19,7 +19,7 @@ jobs:
run:
working-directory: sites/quixbyte.org
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v3.4.1
with:
node-version: 16
Expand Down
27 changes: 10 additions & 17 deletions qb-core/src/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,13 @@ impl QBChangeKind {
/// Returns whether this change has external changes that rely on it.
#[inline(always)]
pub fn is_external(&self) -> bool {
match self {
QBChangeKind::CopyFrom | QBChangeKind::RenameFrom => true,
_ => false,
}
matches!(self, QBChangeKind::CopyFrom | QBChangeKind::RenameFrom)
}

/// Returns whether this change removes the resource.
#[inline(always)]
pub fn is_subtractive(&self) -> bool {
match self {
QBChangeKind::Delete | QBChangeKind::RenameFrom => true,
_ => false,
}
matches!(self, QBChangeKind::Delete | QBChangeKind::RenameFrom)
}
}

Expand All @@ -101,7 +95,7 @@ impl QBChangeMap {
(
resource.clone(),
entries
.into_iter()
.iter()
.filter(|e| &e.timestamp > since)
.cloned()
.collect::<Vec<_>>(),
Expand Down Expand Up @@ -144,9 +138,9 @@ impl QBChangeMap {
self.head = other.head;
}
for (resource, mut other_entries) in other.changes.into_iter() {
let mut entries = self.entries(resource);
let entries = self.entries(resource);
entries.append(&mut other_entries);
Self::_sort(&mut entries);
Self::_sort(entries);
}
}

Expand All @@ -160,8 +154,7 @@ impl QBChangeMap {
pub fn iter(&self) -> impl Iterator<Item = (&QBResource, &QBChange)> {
self.changes
.iter()
.map(|(resource, entries)| entries.into_iter().map(move |change| (resource, change)))
.flatten()
.flat_map(|(resource, entries)| entries.iter().map(move |change| (resource, change)))
.sorted_unstable_by(|a, b| Self::_sort_entry(a.1, b.1))
}

Expand Down Expand Up @@ -211,7 +204,7 @@ impl QBChangeMap {

#[inline(always)]
fn _sort_borrowed(entries: &mut [&QBChange]) {
entries.sort_unstable_by(|a, b| Self::_sort_entry(*a, *b));
entries.sort_unstable_by(|a, b| Self::_sort_entry(a, b));
}

fn _sort_entry(a: &QBChange, b: &QBChange) -> std::cmp::Ordering {
Expand Down Expand Up @@ -282,7 +275,7 @@ impl QBChangeMap {
pub fn get_rename_to(&self, timestamp: &QBTimeStampUnique) -> Option<(usize, &QBResource)> {
self.changes.iter().find_map(|(resource, entries)| {
entries
.into_iter()
.iter()
.position(|change| &change.timestamp == timestamp)
.map(|i| (i, resource))
})
Expand All @@ -296,12 +289,12 @@ impl QBChangeMap {
pub fn merge(&mut self, remote: Self) -> Result<Vec<(QBResource, QBChange)>, String> {
let mut changes = Vec::new();
for (resource, mut remote_entries) in remote.changes.into_iter() {
if let Some(mut entries) = self.changes.get_mut(&resource) {
if let Some(entries) = self.changes.get_mut(&resource) {
// TODO: do this properly
let rchanges = remote_entries.clone();
changes.extend(&mut rchanges.into_iter().map(|e| (resource.clone(), e)));

*entries = Self::_merge(remote_entries, &mut entries);
*entries = Self::_merge(remote_entries, entries);
// TODO: update head
} else {
changes.extend(
Expand Down
2 changes: 1 addition & 1 deletion qb-core/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl QBFS {
QBChangeKind::Create => Some(QBFSChangeKind::Create),
QBChangeKind::Delete => Some(QBFSChangeKind::Delete),
QBChangeKind::UpdateBinary(content) => {
let hash = QBHash::compute(&content);
let hash = QBHash::compute(content);
Some(QBFSChangeKind::Update {
content: content.clone(),
hash,
Expand Down
4 changes: 2 additions & 2 deletions qb-core/src/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl QBIgnoreMapBuilder {
QBFSChangeKind::Delete => _ = self.ignores.remove(&path),
QBFSChangeKind::Create => {}
QBFSChangeKind::Rename { from } => {
let hash = self.ignores.remove(&from).unwrap();
let hash = self.ignores.remove(from).unwrap();
self.ignores.insert(path, hash);
}
QBFSChangeKind::Copy { from } => {
Expand Down Expand Up @@ -164,7 +164,7 @@ impl QBIgnoreMap {
QBFSChangeKind::Delete => _ = self.ignores.remove(&path),
QBFSChangeKind::Create => {}
QBFSChangeKind::Rename { from } => {
let hash = self.ignores.remove(&from).unwrap();
let hash = self.ignores.remove(from).unwrap();
self.ignores.insert(path, hash);
}
QBFSChangeKind::Copy { from } => {
Expand Down
10 changes: 7 additions & 3 deletions qb-core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ impl fmt::Display for QBTimeStamp {
}

/// This struct represents a timestamp recorded on a specific device (no conflicts).
#[derive(
Encode, Decode, Serialize, Deserialize, Clone, Default, Debug, Eq, PartialEq, PartialOrd,
)]
#[derive(Encode, Decode, Serialize, Deserialize, Clone, Default, Debug, Eq, PartialEq)]
pub struct QBTimeStampUnique {
/// The timestamp
pub timestamp: QBTimeStamp,
/// The device id
pub device_id: QBDeviceId,
}

impl PartialOrd for QBTimeStampUnique {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl Ord for QBTimeStampUnique {
/// Compare this unique timestamp to another. This should never return
/// std::cmp::Ordering::Equal for timestamps returned by two seperate invocations
Expand Down
21 changes: 10 additions & 11 deletions qb-daemon/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ pub struct QBCHandle {
impl QBCHandle {
/// Send a message to this handle
pub async fn send(&self, msg: impl Into<QBCResponse>) {
match self.tx.send(msg.into()).await {
Err(err) => warn!("could not send message to handle: {0}", err),
Ok(_) => {}
};
if let Err(err) = self.tx.send(msg.into()).await {
warn!("could not send message to handle: {0}", err);
}
}
}

Expand Down Expand Up @@ -255,7 +254,7 @@ impl QBDaemon {
}

/// Remove an interface
pub async fn remove(&mut self, id: &QBExtId) -> Result<()> {
pub async fn remove(&mut self, id: QBExtId) -> Result<()> {
self.config.ext_autostart.remove(&id);
if self.master.is_attached(&id) {
self.master.detach(&id).await?.await?
Expand Down Expand Up @@ -298,7 +297,7 @@ impl QBDaemon {
name.clone(),
Box::new(move |qb, id, data| {
Box::pin(async move {
qb.attach(id, bitcode::decode::<I>(&data).unwrap()).await?;
qb.attach(id, bitcode::decode::<I>(data).unwrap()).await?;
Ok(())
})
}),
Expand Down Expand Up @@ -333,7 +332,7 @@ impl QBDaemon {
name.clone(),
Box::new(move |qb, id, data| {
Box::pin(async move {
qb.hook(id, bitcode::decode::<H>(&data).unwrap()).await?;
qb.hook(id, bitcode::decode::<H>(data).unwrap()).await?;
Ok(())
})
}),
Expand Down Expand Up @@ -382,12 +381,13 @@ impl QBDaemon {
self.add(caller, name, blob)?;
return Ok(false);
}
QBCRequest::Remove { id } => self.remove(&id).await?,
QBCRequest::Remove { id } => self.remove(id).await?,
QBCRequest::List => {
let handle = self.handles.get(&caller).unwrap();
handle.send(QBCResponse::List { list: self.list() }).await;
return Ok(false);
}
_ => unimplemented!(),
};

Ok(true)
Expand Down Expand Up @@ -419,9 +419,8 @@ where
{
let span = info_span!("handle", id = init.id.to_hex());

match _handle_run(&mut init).instrument(span.clone()).await {
Err(err) => span.in_scope(|| info!("handle finished with: {:?}", err)),
Ok(_) => {}
if let Err(err) = _handle_run(&mut init).instrument(span.clone()).await {
span.in_scope(|| info!("handle finished with: {:?}", err));
}
}

Expand Down
12 changes: 7 additions & 5 deletions qb-daemon/src/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ impl QBMaster {
// unwrap it
let msg = match msg {
QBISlaveMessage::Message(msg) => msg,
_ => unimplemented!(),
};

let span = info_span!("qbi-process", id = id.to_hex());
Expand All @@ -191,7 +192,7 @@ impl QBMaster {
match msg {
QBIMessage::Common { common } => {
// TODO: negotiate this instead
self.devices.set_common(&device_id, common);
self.devices.set_common(device_id, common);
handle.state = QBIState::Available {
device_id: device_id.clone(),
syncing: false,
Expand Down Expand Up @@ -220,7 +221,7 @@ impl QBMaster {
}
};

let handle_common = self.devices.get_common(&device_id);
let handle_common = self.devices.get_common(device_id);

match msg {
QBIMessage::Sync {
Expand All @@ -240,7 +241,7 @@ impl QBMaster {
// find the new common hash
let new_common = self.changemap.head().clone();
debug!("new common: {}", new_common);
self.devices.set_common(&device_id, new_common);
self.devices.set_common(device_id, new_common);

// Send sync to remote
if !*syncing {
Expand All @@ -258,7 +259,7 @@ impl QBMaster {
}
// TODO: negotiate this instead
QBIMessage::Common { common } => {
self.devices.set_common(&device_id, common);
self.devices.set_common(device_id, common);
}
QBIMessage::Broadcast { msg } => broadcast.push(msg),
QBIMessage::Device { .. } => {
Expand Down Expand Up @@ -300,6 +301,7 @@ impl QBMaster {
let context = *context.downcast::<T>().unwrap();
master.attach(QBExtId::generate(), context).await.unwrap();
}
_ => unimplemented!(),
}
})
})),
Expand Down Expand Up @@ -408,7 +410,7 @@ impl QBMaster {
continue;
}

let handle_common = self.devices.get_common(&device_id);
let handle_common = self.devices.get_common(device_id);
let changes = self.changemap.since_cloned(handle_common);

// skip if no changes to sync
Expand Down
1 change: 1 addition & 0 deletions qb-ext-local/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ impl Runner {
info!("stopping...");
break
}
_ => unimplemented!(),
}
},
Some(Ok(event)) = watcher_rx.recv() => {
Expand Down
4 changes: 2 additions & 2 deletions qb-ext-tcp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl QBExtSetup<QBITCPClient> for QBITCPClient {
let dnsname = ServerName::try_from("quixbyte.local").unwrap();
debug!("do TLS handshake");
let mut stream = connector.connect(dnsname, stream).await.unwrap();
self.cert = cert.lock().unwrap().as_ref().unwrap().clone();
self.cert.clone_from(cert.lock().unwrap().as_ref().unwrap());
debug!("successfully extracted certificate");

debug!("do quixbyte protocol handshake");
Expand Down Expand Up @@ -123,7 +123,7 @@ impl SetupVerifier {
}
}

impl<'a> ServerCertVerifier for SetupVerifier {
impl ServerCertVerifier for SetupVerifier {
fn verify_server_cert(
&self,
end_entity: &CertificateDer<'_>,
Expand Down
1 change: 1 addition & 0 deletions qb-ext-tcp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl Runner {
info!("stopping...");
break;
}
_ => unimplemented!(),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions qb-ext/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl QBCId {

/// A request comming from a controlling task.
#[derive(Encode, Decode, Serialize, Deserialize)]
#[non_exhaustive]
pub enum QBCRequest {
/// Add a new interface or hook.
Add {
Expand Down Expand Up @@ -113,6 +114,7 @@ impl fmt::Display for QBCRequest {

/// A response comming from the daemon.
#[derive(Encode, Decode, Serialize, Deserialize)]
#[non_exhaustive]
pub enum QBCResponse {
/// An error has occured.
Error {
Expand Down
4 changes: 3 additions & 1 deletion qb-ext/src/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ impl<T: QBIContext + Any + Send> From<QBHChannel> for QBHInit<T> {
fn from(value: QBHChannel) -> Self {
Self {
channel: value,
_t: PhantomData::default(),
_t: PhantomData,
}
}
}

#[non_exhaustive]
pub enum QBHHostMessage {
Stop,
}

#[non_exhaustive]
pub enum QBHSlaveMessage {
Attach { context: Box<dyn Any + Send> },
}
Expand Down
2 changes: 2 additions & 0 deletions qb-ext/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ impl From<QBIMessage> for QBIHostMessage {

/// a message coming from the interface
#[derive(Encode, Decode, Serialize, Deserialize, Debug, Clone)]
#[non_exhaustive]
pub enum QBISlaveMessage {
/// message
Message(QBIMessage),
}

/// a message coming from the master
#[derive(Encode, Decode, Serialize, Deserialize, Debug, Clone)]
#[non_exhaustive]
pub enum QBIHostMessage {
/// message
Message(QBIMessage),
Expand Down
Loading

0 comments on commit 6f7a87d

Please sign in to comment.