Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy lints #627

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
// off by default, and must be explicitly enabled.
no_signature_verification = !enforce_container_sigpolicy;
let sysroot = &if let Some(sysroot) = sysroot {
ostree::Sysroot::new(Some(&gio::File::for_path(&sysroot)))
ostree::Sysroot::new(Some(&gio::File::for_path(sysroot)))
} else {
ostree::Sysroot::new_default()
};
Expand All @@ -1118,7 +1118,7 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
let booted_stateroot = sysroot
.booted_deployment()
.map(|d| Cow::Owned(d.osname().to_string()));
booted_stateroot.unwrap_or_else(|| {
booted_stateroot.unwrap_or({
Cow::Borrowed(crate::container::deploy::STATEROOT_DEFAULT)
})
};
Expand Down
10 changes: 5 additions & 5 deletions lib/src/container/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ pub(crate) fn parse_manifest_layout<'a>(

let first_layer = manifest
.layers()
.get(0)
.first()
.ok_or_else(|| anyhow!("No layers in manifest"))?;
let target_diffid = config_labels
.and_then(|labels| labels.get(DIFFID_LABEL))
Expand Down Expand Up @@ -1132,7 +1132,7 @@ pub fn query_image_commit(repo: &ostree::Repo, commit: &str) -> Result<Box<Layer
repo.read_commit_detached_metadata(&merge_commit, gio::Cancellable::NONE)?;
let detached_commitmeta = detached_commitmeta
.as_ref()
.map(|v| glib::VariantDict::new(Some(&v)));
.map(|v| glib::VariantDict::new(Some(v)));
let cached_update = detached_commitmeta
.as_ref()
.map(parse_cached_update)
Expand Down Expand Up @@ -1187,9 +1187,9 @@ pub async fn copy(
let opts = glib::VariantDict::new(None);
let refs = [ostree_ref.as_str()];
// Some older archives may have bindings, we don't need to verify them.
opts.insert("disable-verify-bindings", &true);
opts.insert("refs", &&refs[..]);
opts.insert("flags", &(flags.bits() as i32));
opts.insert("disable-verify-bindings", true);
opts.insert("refs", &refs[..]);
opts.insert("flags", flags.bits() as i32);
let options = opts.to_variant();
dest_repo.pull_with_options(srcfd, &options, None, cancellable)?;
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions lib/src/container/unencapsulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub async fn unencapsulate(repo: &ostree::Repo, imgref: &OstreeImageReference) -
/// This is implemented with a background thread using a pipe-to-self,
/// and so there is an additional Future object returned that is a "driver"
/// task and must also be checked for errors.
pub(crate) fn decompress_bridge<'a>(
pub(crate) fn decompress_bridge(
src: impl tokio::io::AsyncBufRead + Send + Unpin + 'static,
is_zstd: bool,
) -> Result<(
Expand Down Expand Up @@ -234,7 +234,7 @@ pub(crate) fn decompress_bridge<'a>(
}

/// Create a decompressor for this MIME type, given a stream of input.
fn new_async_decompressor<'a>(
fn new_async_decompressor(
media_type: &oci_image::MediaType,
src: impl AsyncBufRead + Send + Unpin + 'static,
) -> Result<(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/container/update_detachedmeta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub async fn update_detached_metadata(

// Splice it into both the manifest and config
manifest.layers_mut()[commit_layer_idx] = out_layer_descriptor;
config.rootfs_mut().diff_ids_mut()[commit_layer_idx] = out_layer_diffid.clone();
config.rootfs_mut().diff_ids_mut()[commit_layer_idx].clone_from(&out_layer_diffid);

let labels = ctrcfg.labels_mut().get_or_insert_with(Default::default);
// Nothing to do except in the special case where there's somehow only one
Expand Down
4 changes: 3 additions & 1 deletion lib/src/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,9 @@ impl Fixture {
.timestamp_opt(ostree::commit_get_timestamp(&commit) as i64, 0)
.single()
.unwrap();
let new_ts = ts.add(chrono::Duration::days(1)).timestamp() as u64;
let new_ts = ts
.add(chrono::TimeDelta::try_days(1).expect("one day does not overflow"))
.timestamp() as u64;

// Prepare a transaction
let tx = self.srcrepo.auto_transaction(cancellable)?;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/mountutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn is_mountpoint_impl_statx(root: &Dir, path: &Path) -> Result<Option<bool>> {
) {
Ok(r) => {
let present = (r.stx_attributes_mask & mountroot_flag) > 0;
Ok(present.then(|| r.stx_attributes & mountroot_flag > 0))
Ok(present.then_some(r.stx_attributes & mountroot_flag > 0))
}
Err(e) if e == rustix::io::Errno::NOSYS => Ok(None),
Err(e) => Err(e.into()),
Expand Down
1 change: 0 additions & 1 deletion lib/src/ostree_manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use std::io::Read;
use std::ptr;

use ostree;
use ostree::prelude::{Cast, InputStreamExtManual};
use ostree::{gio, glib};

Expand Down
2 changes: 1 addition & 1 deletion lib/src/ostree_prepareroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) fn load_config(root: &ostree::RepoFile) -> Result<Option<glib::KeyFil
let kf = glib::KeyFile::new();
for path in ["etc", "usr/lib"].into_iter().map(Utf8Path::new) {
let path = &path.join(CONF_PATH);
let f = root.resolve_relative_path(&path);
let f = root.resolve_relative_path(path);
if !f.query_exists(cancellable) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/tar/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ pub(crate) fn export_chunk<W: std::io::Write>(
) -> Result<()> {
// For chunking, we default to format version 1
#[allow(clippy::needless_update)]
let opts = ExportOptions::default();
let opts = ExportOptions;
let writer = &mut OstreeTarWriter::new(repo, commit, out, opts)?;
writer.write_repo_structure()?;
write_chunk(writer, chunk)
Expand All @@ -633,7 +633,7 @@ pub(crate) fn export_final_chunk<W: std::io::Write>(
remainder: chunking::Chunk,
out: &mut tar::Builder<W>,
) -> Result<()> {
let options = ExportOptions::default();
let options = ExportOptions;
let writer = &mut OstreeTarWriter::new(repo, commit_checksum, out, options)?;
// For the final chunk, output the commit object, plus all ostree metadata objects along with
// the containing directories.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/tar/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ impl Importer {
/// Given a tar entry that looks like an object (its path is under ostree/repo/objects/),
/// determine its type and import it.
#[context("Importing object {}", path)]
fn import_object<'b, R: std::io::Read>(
fn import_object<R: std::io::Read>(
&mut self,
entry: tar::Entry<'b, R>,
entry: tar::Entry<'_, R>,
path: &Utf8Path,
cancellable: Option<&gio::Cancellable>,
) -> Result<()> {
Expand Down
9 changes: 5 additions & 4 deletions lib/src/tar/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,10 @@ pub async fn write_tar(
let mut child_stdout = r.stdout.take().unwrap();
let mut child_stderr = r.stderr.take().unwrap();
// Copy the filtered tar stream to child stdin
let mut import_config = TarImportConfig::default();
import_config.allow_nonusr = options.allow_nonusr;
import_config.remap_factory_var = !options.retain_var;
let import_config = TarImportConfig {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is subtle; there may be a better way to handle this but the idea here is we don't want the code to stop compiling when a new field is added to TarImportConfig so I think we still at least want a ..Default::default() at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing it that way runs afoul of needless_update, but that in turn hints at the proper solution in this case - mark the struct as non_exhaustive if it could gain extra fields in the future. Just have to be careful adding that to a public struct since it's a breaking change, but in this instance TarImportConfig is pub(crate) so it's not exposed in the API.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, yeah we should be using non_exhaustive then on other structs. Something to keep in mind for the next API bump.

OTOH I was thinking about folding this repository into bootc, which would simplify things some.

allow_nonusr: options.allow_nonusr,
remap_factory_var: !options.retain_var,
};
let repo_tmpdir = Dir::reopen_dir(&repo.dfd_borrow())?
.open_dir("tmp")
.context("Getting repo tmpdir")?;
Expand Down Expand Up @@ -415,7 +416,7 @@ pub async fn write_tar(
if let Ok((_, child_stderr)) = output_copier.await {
// Avoid trailing newline
let child_stderr = child_stderr.trim();
Err(e.context(format!("{child_stderr}")))?
Err(e.context(child_stderr.to_string()))?
} else {
Err(e)?
}
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ async fn impl_test_container_import_export(chunked: bool) -> Result<()> {
let cfg = skopeo_inspect_config(&srcoci_imgref.to_string())?;
let creation_time =
chrono::NaiveDateTime::parse_from_str(cfg.created().as_deref().unwrap(), "%+").unwrap();
assert_eq!(creation_time.timestamp(), 872879442);
assert_eq!(creation_time.and_utc().timestamp(), 872879442);
let found_cfg = cfg.config().as_ref().unwrap();
// unwrap. Unwrap. UnWrap. UNWRAP!!!!!!!
assert_eq!(
Expand Down
Loading