From d10142dc2681b794d5ba83c7bdeb68d62b4eb796 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 8 Sep 2023 08:45:07 -0400 Subject: [PATCH 1/4] keyfileext: Drop optional_string_list Nothing is using this, and the underlying glib type changed so it's annoying to keep. --- lib/src/keyfileext.rs | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/lib/src/keyfileext.rs b/lib/src/keyfileext.rs index 767cf7b6..8d6e3a6e 100644 --- a/lib/src/keyfileext.rs +++ b/lib/src/keyfileext.rs @@ -9,12 +9,6 @@ pub trait KeyFileExt { fn optional_string(&self, group: &str, key: &str) -> Result, glib::Error>; /// Get a boolean value, but return `None` if the key does not exist. fn optional_bool(&self, group: &str, key: &str) -> Result, glib::Error>; - /// Get a string list value, but return `None` if the key does not exist. - fn optional_string_list( - &self, - group: &str, - key: &str, - ) -> Result>, glib::Error>; } /// Consume a keyfile error, mapping the case where group or key is not found to `Ok(None)`. @@ -42,14 +36,6 @@ impl KeyFileExt for glib::KeyFile { fn optional_bool(&self, group: &str, key: &str) -> Result, glib::Error> { map_keyfile_optional(self.boolean(group, key)) } - - fn optional_string_list( - &self, - group: &str, - key: &str, - ) -> Result>, glib::Error> { - map_keyfile_optional(self.string_list(group, key)) - } } #[cfg(test)] @@ -71,17 +57,5 @@ mod tests { assert_eq!(kf.optional_bool("foo", "bar").unwrap(), None); kf.set_boolean("foo", "somebool", false); assert_eq!(kf.optional_bool("foo", "somebool").unwrap(), Some(false)); - - assert_eq!(kf.optional_string_list("foo", "bar").unwrap(), None); - kf.set_string("foo", "somelist", "one;two;three"); - assert_eq!( - kf.optional_string_list("foo", "somelist").unwrap(), - Some( - vec!["one", "two", "three"] - .iter() - .map(|&v| GString::from(v)) - .collect() - ) - ); } } From 5a32624d5c52deb7b89bab8ca3ba7619f956eddb Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 8 Sep 2023 08:45:49 -0400 Subject: [PATCH 2/4] lib: Bump to ostree 0.19, cap-std-ext 3.0 This is just "keeping up with churn": - Newer versions of glib crates - Bump to cap-std-ext 0.3, which bumps cap-std 2.0 --- lib/Cargo.toml | 4 ++-- lib/src/cli.rs | 6 ++++-- lib/src/container/store.rs | 5 +++-- lib/src/fixture.rs | 21 +++++++++++++++------ lib/src/repair.rs | 2 +- lib/src/tar/export.rs | 10 ++++++---- lib/tests/it/main.rs | 2 +- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/lib/Cargo.toml b/lib/Cargo.toml index d41a174f..f78102c1 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -19,7 +19,7 @@ chrono = "0.4.19" olpc-cjson = "0.1.1" clap = { version= "4.2", features = ["derive"] } clap_mangen = { version = "0.2", optional = true } -cap-std-ext = "2.0" +cap-std-ext = "3.0" flate2 = { features = ["zlib"], default_features = false, version = "1.0.20" } fn-error-context = "0.2.0" futures-util = "0.3.13" @@ -31,7 +31,7 @@ once_cell = "1.9" libc = "0.2.92" libsystemd = "0.6.0" openssl = "0.10.33" -ostree = { features = ["v2022_5", "cap-std-apis"], version = "0.18.0" } +ostree = { features = ["v2022_6"], version = "0.19.0" } pin-project = "1.0" regex = "1.5.4" rustix = { version = "0.37.19", features = ["fs", "process"] } diff --git a/lib/src/cli.rs b/lib/src/cli.rs index 1cf30d68..69336859 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -7,9 +7,11 @@ use anyhow::{Context, Result}; use camino::{Utf8Path, Utf8PathBuf}; +use cap_std_ext::cap_std; use clap::{Parser, Subcommand}; use fn_error_context::context; -use ostree::{cap_std, gio, glib}; +use io_lifetimes::AsFd; +use ostree::{gio, glib}; use std::collections::BTreeMap; use std::ffi::OsString; use std::io::BufWriter; @@ -38,7 +40,7 @@ pub fn parse_base_imgref(s: &str) -> Result { pub fn parse_repo(s: &Utf8Path) -> Result { let repofd = cap_std::fs::Dir::open_ambient_dir(s, cap_std::ambient_authority()) .with_context(|| format!("Opening directory at '{s}'"))?; - ostree::Repo::open_at_dir(&repofd, ".") + ostree::Repo::open_at_dir(repofd.as_fd(), ".") .with_context(|| format!("Opening ostree repository at '{s}'")) } diff --git a/lib/src/container/store.rs b/lib/src/container/store.rs index 8dc0324c..fd66359e 100644 --- a/lib/src/container/store.rs +++ b/lib/src/container/store.rs @@ -12,6 +12,7 @@ use crate::sysroot::SysrootLock; use crate::utils::ResultExt; use anyhow::{anyhow, Context}; use camino::{Utf8Path, Utf8PathBuf}; +use cap_std_ext::cap_std::fs::Dir; use containers_image_proxy::{ImageProxy, OpenedImage}; use fn_error_context::context; use futures_util::TryFutureExt; @@ -839,7 +840,7 @@ impl ImageImporter { let txn = repo.auto_transaction(cancellable)?; let devino = ostree::RepoDevInoCache::new(); - let repodir = repo.dfd_as_dir()?; + let repodir = Dir::reopen_dir(&repo.dfd_borrow())?; let repo_tmp = repodir.open_dir("tmp")?; let td = cap_std_ext::cap_tempfile::TempDir::new_in(&repo_tmp)?; @@ -1310,7 +1311,7 @@ fn compare_file_info(src: &gio::FileInfo, target: &gio::FileInfo) -> bool { #[context("Querying object inode")] fn inode_of_object(repo: &ostree::Repo, checksum: &str) -> Result { - let repodir = repo.dfd_as_dir()?; + let repodir = Dir::reopen_dir(&repo.dfd_borrow())?; let (prefix, suffix) = checksum.split_at(2); let objpath = format!("objects/{}/{}.file", prefix, suffix); let metadata = repodir.symlink_metadata(objpath)?; diff --git a/lib/src/fixture.rs b/lib/src/fixture.rs index 5d66efde..a2035b77 100644 --- a/lib/src/fixture.rs +++ b/lib/src/fixture.rs @@ -10,11 +10,12 @@ use crate::{gio, glib}; use anyhow::{anyhow, Context, Result}; use camino::{Utf8Component, Utf8Path, Utf8PathBuf}; use cap_std::fs::Dir; +use cap_std_ext::cap_std; use cap_std_ext::prelude::CapStdExtCommandExt; use chrono::TimeZone; use fn_error_context::context; +use io_lifetimes::AsFd; use once_cell::sync::Lazy; -use ostree::cap_std; use regex::Regex; use std::borrow::Cow; use std::io::Write; @@ -394,13 +395,21 @@ impl Fixture { .status()?; assert!(st.success()); - let srcrepo = - ostree::Repo::create_at_dir(srcdir_dfd, "repo", ostree::RepoMode::Archive, None) - .context("Creating src/ repo")?; + let srcrepo = ostree::Repo::create_at_dir( + srcdir_dfd.as_fd(), + "repo", + ostree::RepoMode::Archive, + None, + ) + .context("Creating src/ repo")?; dir.create_dir("dest")?; - let destrepo = - ostree::Repo::create_at_dir(&dir, "dest/repo", ostree::RepoMode::BareUser, None)?; + let destrepo = ostree::Repo::create_at_dir( + dir.as_fd(), + "dest/repo", + ostree::RepoMode::BareUser, + None, + )?; Ok(Self { tempdir, dir, diff --git a/lib/src/repair.rs b/lib/src/repair.rs index 235ff84a..4deb35c4 100644 --- a/lib/src/repair.rs +++ b/lib/src/repair.rs @@ -90,7 +90,7 @@ impl InodeCheck { #[doc(hidden)] /// Detect if any commits are potentially incorrect due to inode truncations. pub fn check_inode_collision(repo: &ostree::Repo, verbose: bool) -> Result { - let repo_dir = repo.dfd_as_dir()?; + let repo_dir = Dir::reopen_dir(&repo.dfd_borrow())?; let objects = repo_dir.open_dir("objects")?; println!( diff --git a/lib/src/tar/export.rs b/lib/src/tar/export.rs index 83916945..43f61456 100644 --- a/lib/src/tar/export.rs +++ b/lib/src/tar/export.rs @@ -398,19 +398,21 @@ impl<'a, W: std::io::Write> OstreeTarWriter<'a, W> { let target = meta .symlink_target() .ok_or_else(|| anyhow!("Missing symlink target"))?; + let target = target + .to_str() + .ok_or_else(|| anyhow!("Invalid UTF-8 symlink target: {target:?}"))?; let context = || format!("Writing content symlink: {}", checksum); h.set_entry_type(tar::EntryType::Symlink); h.set_size(0); // Handle //chkconfig, see above - if symlink_is_denormal(&target) { - h.set_link_name_literal(meta.symlink_target().unwrap().as_str()) - .with_context(context)?; + if symlink_is_denormal(target) { + h.set_link_name_literal(target).with_context(context)?; self.out .append_data(&mut h, &path, &mut std::io::empty()) .with_context(context)?; } else { self.out - .append_link(&mut h, &path, target.as_str()) + .append_link(&mut h, &path, target) .with_context(context)?; } } diff --git a/lib/tests/it/main.rs b/lib/tests/it/main.rs index 1bbbbea1..6d514d7d 100644 --- a/lib/tests/it/main.rs +++ b/lib/tests/it/main.rs @@ -1,10 +1,10 @@ use anyhow::{Context, Result}; use camino::Utf8Path; use cap_std::fs::{Dir, DirBuilder}; +use cap_std_ext::cap_std; use containers_image_proxy::oci_spec; use containers_image_proxy::oci_spec::image::ImageManifest; use once_cell::sync::Lazy; -use ostree::cap_std; use ostree_ext::chunking::ObjectMetaSized; use ostree_ext::container::{store, ManifestDiff}; use ostree_ext::container::{ From ab4045d992a779dd3c2834f6225d16017f6772a2 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 8 Sep 2023 09:24:57 -0400 Subject: [PATCH 3/4] lib: Bump to rustix 0.38 Again just keeping up. --- lib/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cargo.toml b/lib/Cargo.toml index f78102c1..9e167a26 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -34,7 +34,7 @@ openssl = "0.10.33" ostree = { features = ["v2022_6"], version = "0.19.0" } pin-project = "1.0" regex = "1.5.4" -rustix = { version = "0.37.19", features = ["fs", "process"] } +rustix = { version = "0.38", features = ["fs", "process"] } serde = { features = ["derive"], version = "1.0.125" } serde_json = "1.0.64" tar = "0.4.38" From 0be18838bda8309b0f6df3e0bf542aab3d9e2b0a Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 8 Sep 2023 09:25:48 -0400 Subject: [PATCH 4/4] lib: Bump semver to 0.12 Because we bumped ostree. --- lib/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 9e167a26..d8adc3dc 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" name = "ostree-ext" readme = "README.md" repository = "https://github.com/ostreedev/ostree-rs-ext" -version = "0.11.6" +version = "0.12.0" rust-version = "1.70.0" [dependencies]