Skip to content

Commit 0205e92

Browse files
committed
Update cap-std-ext, use new open_dir_noxdev API
I moved the code there; I plan to use open_dir_noxdev in the tmpfiles code too which can't depend on lib/util. Signed-off-by: Colin Walters <[email protected]>
1 parent 3461dde commit 0205e92

File tree

4 files changed

+10
-71
lines changed

4 files changed

+10
-71
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/install.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use crate::progress_jsonl::ProgressWriter;
5858
use crate::spec::ImageReference;
5959
use crate::store::Storage;
6060
use crate::task::Task;
61-
use crate::utils::{open_dir_noxdev, sigpolicy_from_opt};
61+
use crate::utils::sigpolicy_from_opt;
6262

6363
/// The toplevel boot directory
6464
const BOOT: &str = "boot";
@@ -1579,7 +1579,7 @@ fn remove_all_in_dir_no_xdev(d: &Dir, mount_err: bool) -> Result<()> {
15791579
let name = entry.file_name();
15801580
let etype = entry.file_type()?;
15811581
if etype == FileType::dir() {
1582-
if let Some(subdir) = open_dir_noxdev(d, &name)? {
1582+
if let Some(subdir) = d.open_dir_noxdev(&name)? {
15831583
remove_all_in_dir_no_xdev(&subdir, mount_err)?;
15841584
d.remove_dir(&name)?;
15851585
} else if mount_err {

lib/src/lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ fn check_utf8(dir: &Dir) -> LintResult {
314314
return lint_err(format!("/{strname}: Found non-utf8 symlink target"));
315315
}
316316
} else if ifmt.is_dir() {
317-
let Some(subdir) = crate::utils::open_dir_noxdev(dir, entry.file_name())? else {
317+
let Some(subdir) = dir.open_dir_noxdev(entry.file_name())? else {
318318
continue;
319319
};
320320
if let Err(err) = check_utf8(&subdir)? {

lib/src/utils.rs

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::future::Future;
22
use std::io::Write;
3-
use std::os::fd::{AsFd, BorrowedFd, OwnedFd};
4-
use std::path::Path;
3+
use std::os::fd::BorrowedFd;
54
use std::process::Command;
65
use std::time::Duration;
76

@@ -17,7 +16,6 @@ use libsystemd::logging::journal_print;
1716
use ostree::glib;
1817
use ostree_ext::container::SignatureSource;
1918
use ostree_ext::ostree;
20-
use rustix::path::Arg;
2119

2220
/// Try to look for keys injected by e.g. rpm-ostree requesting machine-local
2321
/// changes; if any are present, return `true`.
@@ -54,33 +52,6 @@ pub(crate) fn deployment_fd(
5452
sysroot_dir.open_dir(&dirpath).map_err(Into::into)
5553
}
5654

57-
/// A thin wrapper for [`openat2`] but that retries on interruption.
58-
pub fn openat2_with_retry(
59-
dirfd: impl AsFd,
60-
path: impl AsRef<Path>,
61-
oflags: rustix::fs::OFlags,
62-
mode: rustix::fs::Mode,
63-
resolve: rustix::fs::ResolveFlags,
64-
) -> rustix::io::Result<OwnedFd> {
65-
let dirfd = dirfd.as_fd();
66-
let path = path.as_ref();
67-
// We loop forever on EAGAIN right now. The cap-std version loops just 4 times,
68-
// which seems really arbitrary.
69-
path.into_with_c_str(|path_c_str| 'start: loop {
70-
match rustix::fs::openat2(dirfd, path_c_str, oflags, mode, resolve) {
71-
Ok(file) => {
72-
return Ok(file);
73-
}
74-
Err(rustix::io::Errno::AGAIN | rustix::io::Errno::INTR) => {
75-
continue 'start;
76-
}
77-
Err(e) => {
78-
return Err(e);
79-
}
80-
}
81-
})
82-
}
83-
8455
/// Given an mount option string list like foo,bar=baz,something=else,ro parse it and find
8556
/// the first entry like $optname=
8657
/// This will not match a bare `optname` without an equals.
@@ -110,25 +81,6 @@ pub(crate) fn open_dir_remount_rw(root: &Dir, target: &Utf8Path) -> Result<Dir>
11081
root.open_dir(target).map_err(anyhow::Error::new)
11182
}
11283

113-
/// Open the target directory, but return Ok(None) if this would cross a mount point.
114-
pub fn open_dir_noxdev(
115-
parent: &Dir,
116-
path: impl AsRef<std::path::Path>,
117-
) -> std::io::Result<Option<Dir>> {
118-
use rustix::fs::{Mode, OFlags, ResolveFlags};
119-
match openat2_with_retry(
120-
parent,
121-
path,
122-
OFlags::CLOEXEC | OFlags::DIRECTORY | OFlags::NOFOLLOW,
123-
Mode::empty(),
124-
ResolveFlags::NO_XDEV | ResolveFlags::BENEATH,
125-
) {
126-
Ok(r) => Ok(Some(Dir::reopen_dir(&r)?)),
127-
Err(e) if e == rustix::io::Errno::XDEV => Ok(None),
128-
Err(e) => return Err(e.into()),
129-
}
130-
}
131-
13284
/// Given a target path, remove its immutability if present
13385
#[context("Removing immutable flag from {target}")]
13486
pub(crate) fn remove_immutability(root: &Dir, target: &Utf8Path) -> Result<()> {
@@ -236,8 +188,6 @@ pub(crate) fn digested_pullspec(image: &str, digest: &str) -> String {
236188

237189
#[cfg(test)]
238190
mod tests {
239-
use cap_std_ext::cap_std;
240-
241191
use super::*;
242192

243193
#[test]
@@ -273,15 +223,4 @@ mod tests {
273223
SignatureSource::ContainerPolicyAllowInsecure
274224
);
275225
}
276-
277-
#[test]
278-
fn test_open_noxdev() -> Result<()> {
279-
let root = Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
280-
// This hard requires the host setup to have /usr/bin on the same filesystem as /
281-
let usr = Dir::open_ambient_dir("/usr", cap_std::ambient_authority())?;
282-
assert!(open_dir_noxdev(&usr, "bin").unwrap().is_some());
283-
// Requires a mounted /proc, but that also seems ane.
284-
assert!(open_dir_noxdev(&root, "proc").unwrap().is_none());
285-
Ok(())
286-
}
287226
}

0 commit comments

Comments
 (0)