Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
flxoacn committed Oct 22, 2024
1 parent 18e50ec commit 2ee1906
Show file tree
Hide file tree
Showing 9 changed files with 564 additions and 718 deletions.
1,217 changes: 537 additions & 680 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions northstar-runtime/src/common/version.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use serde::{Deserialize, Serialize};
use std::{cmp::Ordering, fmt, str::FromStr};
use std::{
cmp::Ordering,
fmt::{self, Display},
str::FromStr,
};
use thiserror::Error;

/// Parsing error
Expand Down Expand Up @@ -164,9 +168,9 @@ impl FromStr for VersionReq {
}
}

impl ToString for VersionReq {
fn to_string(&self) -> String {
self.inner.to_string()
impl Display for VersionReq {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.inner)
}
}

Expand Down
10 changes: 0 additions & 10 deletions northstar-runtime/src/npk/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,6 @@ impl FromStr for Manifest {
}
}

impl ToString for Manifest {
#[allow(clippy::unwrap_used)]
fn to_string(&self) -> String {
// A `Manifest` is convertible to `String` as long as its implementation of `Serialize` does
// not return an error. This should never happen for the types that we use in `Manifest` so
// we can safely use .unwrap() here.
serde_yaml::to_string(self).expect("failed to serialize manifest")
}
}

/// Validate manifest.
fn validate(manifest: &Manifest) -> Result<(), ValidationError> {
// Most optionals in the manifest are not valid for a resource container
Expand Down
11 changes: 6 additions & 5 deletions northstar-runtime/src/npk/npk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ impl<'a> NpkBuilder<'a> {
zip.set_comment(meta_str);

// Add manifest.
let manifest_str = manifest.to_string();
let manifest_str =
serde_yaml::to_string(manifest).context("failed to serialize manifest")?;
zip.start_file(MANIFEST_NAME, options)
.context("failed to write manifest to NPK")?;
zip.write_all(manifest_str.as_bytes())
Expand Down Expand Up @@ -599,8 +600,8 @@ pub fn unpack_with(path: &Path, out: &Path, unsquashfs: &Path) -> Result<(), Err

let mut cmd = Command::new(unsquashfs);
cmd.arg("-dest")
.arg(&root.display().to_string())
.arg(&fsimg.display().to_string());
.arg(root.display().to_string())
.arg(fsimg.display().to_string());
cmd.output().context("failed to unsquashfs")?;
fs::remove_file(&fsimg).with_context(|| format!("failed to remove {}", &fsimg.display()))?;

Expand Down Expand Up @@ -852,8 +853,8 @@ fn mksquashfs(
cmd.stdout(process::Stdio::piped())
.stderr(process::Stdio::piped())
.stdin(process::Stdio::piped())
.arg(&root.display().to_string())
.arg(&image.display().to_string())
.arg(root.display().to_string())
.arg(image.display().to_string())
.arg("-noappend")
.arg("-no-progress")
.arg("-info")
Expand Down
7 changes: 4 additions & 3 deletions northstar-runtime/src/runtime/cgroups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,19 @@ impl MemoryMonitor {
// This task stops when the main loop receiver closes
let task = {
let stop = token.clone();
let mut inotify = Inotify::init().expect("Error while initializing inotify instance");
let inotify = Inotify::init().expect("Error while initializing inotify instance");

inotify
.add_watch(&path, WatchMask::MODIFY)
.watches()
.add(&path, WatchMask::MODIFY)
.expect("failed to add file watch");

task::spawn(async move {
debug!("Listening for v2 oom events of {}", container);

let mut buffer = [0; 1024];
let mut stream = inotify
.event_stream(&mut buffer)
.into_event_stream(&mut buffer)
.expect("failed to initialize inotify event stream");

'outer: loop {
Expand Down
21 changes: 6 additions & 15 deletions northstar-runtime/src/runtime/fork/init/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,12 @@ fn bind(root: &Path, target: &Path, host: &Path, options: &mount::MountOptions)
if host.exists() {
let rw = options.contains(&mount::MountOption::Rw);
let mut mounts = Vec::with_capacity(if rw { 2 } else { 1 });
if options.is_empty() {
log::debug!(
"Adding {} on {} with flags {}",
host.display(),
target.display(),
options
);
} else {
log::debug!(
"Adding {} on {} with flags {}",
host.display(),
target.display(),
options
);
}
log::debug!(
"Adding {} on {} with flags {}",
host.display(),
target.display(),
options
);
let source = host.to_owned();
let target = root.join_strip(target);
let mut flags = options_to_flags(options);
Expand Down
1 change: 1 addition & 0 deletions northstar-runtime/src/runtime/ipc/raw_fd_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{io, io::Result, os::unix::prelude::AsRawFd};

pub trait RawFdExt: AsRawFd {
/// Returns true of self is set to non-blocking.
#[allow(unused)]
fn is_nonblocking(&self) -> Result<bool>;

/// Set non-blocking mode.
Expand Down
1 change: 1 addition & 0 deletions northstar-runtime/src/runtime/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod cgroups;
mod console;
mod debug;
#[allow(unused)]
mod devicemapper;
mod env;
mod error;
Expand Down
2 changes: 1 addition & 1 deletion northstar-runtime/src/runtime/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl Repository for MemRepository {
.context("failed to add memfd seals")?;

// Forget fd - it's owned by file
fd.into_raw_fd();
let _ = fd.into_raw_fd();

file.set_nonblocking(false)
.context("failed to set blocking")?;
Expand Down

0 comments on commit 2ee1906

Please sign in to comment.