Skip to content

Commit

Permalink
Merge pull request ostreedev#261 from cgwalters/tar-split-prep4
Browse files Browse the repository at this point in the history
bootabletree: New module with helpers for bootable ostree commits
  • Loading branch information
jmarrero authored Mar 7, 2022
2 parents 207e790 + 7b8f483 commit f21405f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/src/bootabletree.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Helper functions for bootable OSTrees.
use anyhow::Result;
use ostree::gio;
use ostree::prelude::*;

const MODULES: &str = "/usr/lib/modules";

/// Find the kernel modules directory in a bootable OSTree commit.
pub fn find_kernel_dir(
root: &gio::File,
cancellable: Option<&gio::Cancellable>,
) -> Result<Option<gio::File>> {
let moddir = root.resolve_relative_path(MODULES);
let e = moddir.enumerate_children(
"standard::name",
gio::FileQueryInfoFlags::NOFOLLOW_SYMLINKS,
cancellable,
)?;
let mut r = None;
for child in e.clone() {
let child = &child?;
let childpath = e.child(child);
if child.file_type() == gio::FileType::Directory && r.replace(childpath).is_some() {
anyhow::bail!("Found multiple subdirectories in {}", MODULES);
}
}
Ok(r)
}
1 change: 1 addition & 0 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Result<T> = anyhow::Result<T>;
// Import global functions.
mod globals;

pub mod bootabletree;
pub mod cli;
pub mod container;
pub mod container_utils;
Expand Down
12 changes: 12 additions & 0 deletions lib/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use ostree_ext::container::store::PrepareResult;
use ostree_ext::container::{
Config, ImageReference, OstreeImageReference, SignatureSource, Transport,
};
use ostree_ext::prelude::FileExt;
use ostree_ext::tar::TarImportOptions;
use ostree_ext::{gio, glib};
use sh_inline::bash_in;
Expand Down Expand Up @@ -300,6 +301,17 @@ async fn test_tar_import_export() -> Result<()> {
"#,
imported_commit = imported_commit.as_str()
)?;

let (root, _) = fixture
.destrepo()
.read_commit(&imported_commit, gio::NONE_CANCELLABLE)?;
let kdir = ostree_ext::bootabletree::find_kernel_dir(&root, gio::NONE_CANCELLABLE)?;
let kdir = kdir.unwrap();
assert_eq!(
kdir.basename().unwrap().to_str().unwrap(),
"5.10.18-200.x86_64"
);

Ok(())
}

Expand Down

0 comments on commit f21405f

Please sign in to comment.