11use std:: future:: Future ;
22use std:: io:: Write ;
3- use std:: os:: fd:: { AsFd , BorrowedFd , OwnedFd } ;
4- use std:: path:: Path ;
3+ use std:: os:: fd:: BorrowedFd ;
54use std:: process:: Command ;
65use std:: time:: Duration ;
76
@@ -17,7 +16,6 @@ use libsystemd::logging::journal_print;
1716use ostree:: glib;
1817use ostree_ext:: container:: SignatureSource ;
1918use 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}" ) ]
13486pub ( 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) ]
238190mod 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