Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #627 from jeckersb/clippy-fixups
Browse files Browse the repository at this point in the history
Fix clippy lints
  • Loading branch information
cgwalters authored May 21, 2024
2 parents 0f538a8 + 31603f0 commit 6945225
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 23 deletions.
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 {
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

0 comments on commit 6945225

Please sign in to comment.