composepost: uniform results and visibility for cxxbridge
This aligns the result types and visibility for all post-processing functions that are bridged to C++.
This commit is contained in:
parent
a700b2e74b
commit
8e231b5aad
@ -1,13 +1,9 @@
|
|||||||
/*
|
//! Logic for post-processing a filesystem tree, server-side.
|
||||||
* Copyright (C) 2018 Red Hat, Inc.
|
//!
|
||||||
*
|
//! This code runs server side to "postprocess" a filesystem tree (usually
|
||||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
//! containing mostly RPMs) in order to prepare it as an OSTree commit.
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
//! Code run server side to "postprocess"
|
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||||
//! a filesystem tree (usually containing mostly RPMs) in
|
|
||||||
//! order to prepare it as an OSTree commit.
|
|
||||||
|
|
||||||
use crate::bwrap;
|
use crate::bwrap;
|
||||||
use crate::cxxrsutil::CxxResult;
|
use crate::cxxrsutil::CxxResult;
|
||||||
@ -42,10 +38,7 @@ fn dir_move_if_exists(src: &openat::Dir, dest: &openat::Dir, name: &str) -> Resu
|
|||||||
/// This is hardcoded; in the future we may make more things configurable,
|
/// This is hardcoded; in the future we may make more things configurable,
|
||||||
/// but the goal is for all state to be in `/etc` and `/var`.
|
/// but the goal is for all state to be in `/etc` and `/var`.
|
||||||
#[context("Init rootfs")]
|
#[context("Init rootfs")]
|
||||||
pub(crate) fn compose_init_rootfs(
|
fn compose_init_rootfs(rootfs_dfd: &openat::Dir, treefile: &mut Treefile) -> Result<()> {
|
||||||
rootfs_dfd: &openat::Dir,
|
|
||||||
treefile: &mut Treefile,
|
|
||||||
) -> CxxResult<()> {
|
|
||||||
use nix::fcntl::OFlag;
|
use nix::fcntl::OFlag;
|
||||||
println!("Initializing rootfs");
|
println!("Initializing rootfs");
|
||||||
|
|
||||||
@ -91,12 +84,14 @@ pub(crate) fn compose_init_rootfs(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Prepare rootfs for commit.
|
||||||
|
///
|
||||||
/// Initialize a basic root filesystem in @target_root_dfd, then walk over the
|
/// Initialize a basic root filesystem in @target_root_dfd, then walk over the
|
||||||
/// root filesystem in @src_rootfs_fd and take the basic content (/usr, /boot, /var)
|
/// root filesystem in @src_rootfs_fd and take the basic content (/usr, /boot, /var)
|
||||||
/// and cherry pick only specific bits of the rest of the toplevel like compatibility
|
/// and cherry pick only specific bits of the rest of the toplevel like compatibility
|
||||||
/// symlinks (e.g. /lib64 -> /usr/lib64) if they exist.
|
/// symlinks (e.g. /lib64 -> /usr/lib64) if they exist.
|
||||||
#[context("Preparing rootfs for commit")]
|
#[context("Preparing rootfs for commit")]
|
||||||
pub(crate) fn compose_prepare_rootfs(
|
pub fn compose_prepare_rootfs(
|
||||||
src_rootfs_dfd: i32,
|
src_rootfs_dfd: i32,
|
||||||
target_rootfs_dfd: i32,
|
target_rootfs_dfd: i32,
|
||||||
treefile: &mut Treefile,
|
treefile: &mut Treefile,
|
||||||
@ -211,9 +206,13 @@ fn postprocess_subs_dist(rootfs_dfd: &openat::Dir) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is called from rpmostree_postprocess_final(); think of
|
/// Final processing steps.
|
||||||
// it as the bits of that function that we've chosen to implement in Rust.
|
///
|
||||||
pub(crate) fn compose_postprocess_final(rootfs_dfd: i32) -> CxxResult<()> {
|
/// This function is called from rpmostree_postprocess_final(); think of
|
||||||
|
/// it as the bits of that function that we've chosen to implement in Rust.
|
||||||
|
/// It takes care of all things that are really required to use rpm-ostree
|
||||||
|
/// on the target host.
|
||||||
|
pub fn compose_postprocess_final(rootfs_dfd: i32) -> CxxResult<()> {
|
||||||
let rootfs_dfd = crate::ffiutil::ffi_view_openat_dir(rootfs_dfd);
|
let rootfs_dfd = crate::ffiutil::ffi_view_openat_dir(rootfs_dfd);
|
||||||
let tasks = [
|
let tasks = [
|
||||||
postprocess_useradd,
|
postprocess_useradd,
|
||||||
@ -273,7 +272,7 @@ fn compose_postprocess_scripts(
|
|||||||
rootfs_dfd: &openat::Dir,
|
rootfs_dfd: &openat::Dir,
|
||||||
treefile: &mut Treefile,
|
treefile: &mut Treefile,
|
||||||
unified_core: bool,
|
unified_core: bool,
|
||||||
) -> CxxResult<()> {
|
) -> Result<()> {
|
||||||
// Execute the anonymous (inline) scripts.
|
// Execute the anonymous (inline) scripts.
|
||||||
for (i, script) in treefile.parsed.postprocess.iter().flatten().enumerate() {
|
for (i, script) in treefile.parsed.postprocess.iter().flatten().enumerate() {
|
||||||
let binpath = format!("/usr/bin/rpmostree-postprocess-inline-{}", i);
|
let binpath = format!("/usr/bin/rpmostree-postprocess-inline-{}", i);
|
||||||
@ -311,18 +310,19 @@ fn compose_postprocess_scripts(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Logic for handling treefile `remove-files`.
|
||||||
#[context("Handling `remove-files`")]
|
#[context("Handling `remove-files`")]
|
||||||
pub(crate) fn compose_postprocess_remove_files(
|
pub fn compose_postprocess_remove_files(
|
||||||
rootfs_dfd: &openat::Dir,
|
rootfs_dfd: &openat::Dir,
|
||||||
treefile: &mut Treefile,
|
treefile: &mut Treefile,
|
||||||
) -> Result<()> {
|
) -> CxxResult<()> {
|
||||||
for name in treefile.parsed.remove_files.iter().flatten() {
|
for name in treefile.parsed.remove_files.iter().flatten() {
|
||||||
let p = Path::new(name);
|
let p = Path::new(name);
|
||||||
if p.is_absolute() {
|
if p.is_absolute() {
|
||||||
return Err(anyhow!("Invalid absolute path: {}", name).into());
|
return Err(anyhow!("Invalid absolute path: {}", name).into());
|
||||||
}
|
}
|
||||||
if name.contains("..") {
|
if name.contains("..") {
|
||||||
return Err(anyhow!("Invalid .. in path: {}", name).into());
|
return Err(anyhow!("Invalid '..' in path: {}", name).into());
|
||||||
}
|
}
|
||||||
println!("Deleting: {}", name);
|
println!("Deleting: {}", name);
|
||||||
rootfs_dfd.remove_all(name)?;
|
rootfs_dfd.remove_all(name)?;
|
||||||
@ -388,7 +388,7 @@ fn compose_postprocess_rpmdb(rootfs_dfd: &openat::Dir) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Rust portion of rpmostree_treefile_postprocessing()
|
/// Rust portion of rpmostree_treefile_postprocessing()
|
||||||
pub(crate) fn compose_postprocess(
|
pub fn compose_postprocess(
|
||||||
rootfs_dfd: i32,
|
rootfs_dfd: i32,
|
||||||
treefile: &mut Treefile,
|
treefile: &mut Treefile,
|
||||||
next_version: &str,
|
next_version: &str,
|
||||||
@ -424,7 +424,7 @@ pub(crate) fn compose_postprocess(
|
|||||||
|
|
||||||
/// Implementation of the treefile `mutate-os-release` field.
|
/// Implementation of the treefile `mutate-os-release` field.
|
||||||
#[context("Updating os-release with commit version")]
|
#[context("Updating os-release with commit version")]
|
||||||
pub(crate) fn compose_postprocess_mutate_os_release(
|
fn compose_postprocess_mutate_os_release(
|
||||||
rootfs_dfd: &openat::Dir,
|
rootfs_dfd: &openat::Dir,
|
||||||
treefile: &mut Treefile,
|
treefile: &mut Treefile,
|
||||||
next_version: &str,
|
next_version: &str,
|
||||||
@ -465,11 +465,7 @@ pub(crate) fn compose_postprocess_mutate_os_release(
|
|||||||
|
|
||||||
/// Given the contents of a /usr/lib/os-release file,
|
/// Given the contents of a /usr/lib/os-release file,
|
||||||
/// update the `VERSION` and `PRETTY_NAME` fields.
|
/// update the `VERSION` and `PRETTY_NAME` fields.
|
||||||
pub(crate) fn mutate_os_release_contents(
|
fn mutate_os_release_contents(contents: &str, base_version: &str, next_version: &str) -> String {
|
||||||
contents: &str,
|
|
||||||
base_version: &str,
|
|
||||||
next_version: &str,
|
|
||||||
) -> String {
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
for line in contents.lines() {
|
for line in contents.lines() {
|
||||||
if line.is_empty() {
|
if line.is_empty() {
|
||||||
@ -540,11 +536,13 @@ fn add_altfiles(buf: &str) -> Result<String> {
|
|||||||
Ok(r)
|
Ok(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add `altfiles` entries to `nsswitch.conf`.
|
||||||
|
///
|
||||||
/// rpm-ostree currently depends on `altfiles`
|
/// rpm-ostree currently depends on `altfiles`
|
||||||
#[context("Adding altfiles to /etc/nsswitch.conf")]
|
#[context("Adding altfiles to /etc/nsswitch.conf")]
|
||||||
pub(crate) fn composepost_nsswitch_altfiles(rootfs_dfd: i32) -> CxxResult<()> {
|
pub fn composepost_nsswitch_altfiles(rootfs_dfd: i32) -> CxxResult<()> {
|
||||||
let path = "usr/etc/nsswitch.conf";
|
|
||||||
let rootfs_dfd = &crate::ffiutil::ffi_view_openat_dir(rootfs_dfd);
|
let rootfs_dfd = &crate::ffiutil::ffi_view_openat_dir(rootfs_dfd);
|
||||||
|
let path = "usr/etc/nsswitch.conf";
|
||||||
let nsswitch = rootfs_dfd.read_to_string(path)?;
|
let nsswitch = rootfs_dfd.read_to_string(path)?;
|
||||||
let nsswitch = add_altfiles(&nsswitch)?;
|
let nsswitch = add_altfiles(&nsswitch)?;
|
||||||
rootfs_dfd.write_file_contents(path, 0o644, nsswitch.as_bytes())?;
|
rootfs_dfd.write_file_contents(path, 0o644, nsswitch.as_bytes())?;
|
||||||
|
Loading…
Reference in New Issue
Block a user