From d71d9c0d985b1c80be3bdbdd2f6229d4909675d4 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 2 Jun 2024 09:42:52 -0400 Subject: [PATCH] Update oci-spec, drop once-cell and libc Update to the latest semver for oci-spec. While we're here, switch to using the std OnceCell and drop the unused libc dependency. Signed-off-by: Colin Walters --- Cargo.toml | 6 ++---- src/imageproxy.rs | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 59d45a5..1340d3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,16 +5,14 @@ license = "MIT OR Apache-2.0" name = "containers-image-proxy" readme = "README.md" repository = "https://github.com/containers/containers-image-proxy-rs" -version = "0.5.8" +version = "0.5.9" rust-version = "1.70.0" [dependencies] anyhow = "1.0" fn-error-context = "0.2.0" futures-util = "0.3.13" -oci-spec = "0.5.5" -once_cell = "1.9.0" -libc = "0.2" +oci-spec = "0.6.5" rustix = { version = "0.38", features = ["process", "net"] } serde = { features = ["derive"], version = "1.0.125" } serde_json = "1.0.64" diff --git a/src/imageproxy.rs b/src/imageproxy.rs index 5798cae..04f8775 100644 --- a/src/imageproxy.rs +++ b/src/imageproxy.rs @@ -8,7 +8,6 @@ use anyhow::{anyhow, Context, Result}; use cap_std_ext::prelude::CapStdExtCommandExt; use cap_std_ext::{cap_std, cap_tempfile}; use futures_util::Future; -use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use std::fs::File; use std::ops::Range; @@ -17,7 +16,7 @@ use std::os::unix::prelude::CommandExt; use std::path::PathBuf; use std::pin::Pin; use std::process::{Command, Stdio}; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, Mutex, OnceLock}; use tokio::io::{AsyncBufRead, AsyncReadExt}; use tokio::sync::Mutex as AsyncMutex; use tokio::task::JoinError; @@ -38,11 +37,16 @@ pub const RESERVED_FD_RANGE: Range = 100..200; // Note that payload data (non-metadata) should go over a pipe file descriptor. const MAX_MSG_SIZE: usize = 32 * 1024; -// Introduced in https://github.com/containers/skopeo/pull/1523 -static BASE_PROTO_VERSION: Lazy = - Lazy::new(|| semver::VersionReq::parse("0.2.3").unwrap()); -static LAYER_INFO_PROTO_VERSION: Lazy = - Lazy::new(|| semver::VersionReq::parse("0.2.5").unwrap()); +fn base_proto_version() -> &'static semver::VersionReq { + // Introduced in https://github.com/containers/skopeo/pull/1523 + static BASE_PROTO_VERSION: OnceLock = OnceLock::new(); + BASE_PROTO_VERSION.get_or_init(|| semver::VersionReq::parse("0.2.3").unwrap()) +} + +fn layer_info_proto_version() -> &'static semver::VersionReq { + static LAYER_INFO_PROTO_VERSION: OnceLock = OnceLock::new(); + LAYER_INFO_PROTO_VERSION.get_or_init(|| semver::VersionReq::parse("0.2.5").unwrap()) +} #[derive(Serialize)] struct Request { @@ -279,7 +283,7 @@ impl ImageProxy { tracing::debug!("Remote protocol version: {protover}"); let protover = semver::Version::parse(protover.as_str())?; // Previously we had a feature to opt-in to requiring newer versions using `if cfg!()`. - let supported = &*BASE_PROTO_VERSION; + let supported = base_proto_version(); if !supported.matches(&protover) { return Err(anyhow!( "Unsupported protocol version {} (compatible: {})", @@ -500,7 +504,7 @@ impl ImageProxy { img: &OpenedImage, ) -> Result>> { tracing::debug!("Getting layer info"); - if !LAYER_INFO_PROTO_VERSION.matches(&self.protover) { + if !layer_info_proto_version().matches(&self.protover) { return Ok(None); } let reply = self.impl_request("GetLayerInfo", [img.0]).await?;