forked from ostreedev/ostree-rs-ext
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support non-
/usr
content if ostree configured with overlayfs
This pairs with ostreedev/ostree#3114 Basically if ostree has an overlayfs (whether writable or a readonly composefs), we're safe to handle non-`/usr` content. However, we still *always* drop content from the "API filesystems" like `/run`, `/dev` etc. Because really, no one should be adding stuff there.
- Loading branch information
Showing
6 changed files
with
121 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//! Logic related to parsing ostree-prepare-root.conf. | ||
//! | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
use crate::keyfileext::KeyFileExt; | ||
use anyhow::{Context, Result}; | ||
use camino::Utf8Path; | ||
use ostree::prelude::FileExt; | ||
use ostree::{gio, glib}; | ||
|
||
pub(crate) const CONF_PATH: &str = "ostree/prepare-root.conf"; | ||
|
||
pub(crate) fn load_config(root: &ostree::RepoFile) -> Result<Option<glib::KeyFile>> { | ||
let cancellable = gio::Cancellable::NONE; | ||
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); | ||
if !f.query_exists(cancellable) { | ||
continue; | ||
} | ||
let contents = f.load_contents(cancellable)?.0; | ||
let contents = String::from_utf8(contents)?; | ||
kf.load_from_data(&contents, glib::KeyFileFlags::NONE) | ||
.with_context(|| format!("Parsing {path}"))?; | ||
tracing::debug!("Loaded {path}"); | ||
return Ok(Some(kf)); | ||
} | ||
tracing::debug!("No {CONF_PATH} found"); | ||
Ok(None) | ||
} | ||
|
||
/// Query whether the target root has the `root.transient` key | ||
/// which sets up a transient overlayfs. | ||
pub(crate) fn overlayfs_root_enabled(root: &ostree::RepoFile) -> Result<bool> { | ||
if let Some(config) = load_config(root)? { | ||
overlayfs_enabled_in_config(&config) | ||
} else { | ||
Ok(false) | ||
} | ||
} | ||
|
||
/// Query whether the config uses an overlayfs model (composefs or plain overlayfs). | ||
pub fn overlayfs_enabled_in_config(config: &glib::KeyFile) -> Result<bool> { | ||
let root_transient = config | ||
.optional_bool("root", "transient")? | ||
.unwrap_or_default(); | ||
let required_composefs = config | ||
.optional_string("composefs", "enabled")? | ||
.map(|s| s.as_str() == "yes") | ||
.unwrap_or_default(); | ||
Ok(root_transient || required_composefs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters