Move occupy and unoccupy out of base crate

This commit is contained in:
topjohnwu
2025-11-29 00:13:41 -08:00
committed by John Wu
parent f7ce9c38e1
commit 5d6b703622
3 changed files with 55 additions and 54 deletions
+1 -50
View File
@@ -1,5 +1,4 @@
use crate::WalkResult::{Continue, Skip};
use crate::{Directory, LibcReturn, OsResult, ResultExt, Utf8CStr, Utf8CStrBufArr};
use crate::{LibcReturn, OsResult, Utf8CStr};
use nix::mount::{MntFlags, MsFlags, mount, umount2};
impl Utf8CStr {
@@ -82,52 +81,4 @@ impl Utf8CStr {
)
.check_os_err("set_mount_private", Some(self), None)
}
pub fn occupy(&self) {
Directory::open(self)
.map(|mut dir| {
dir.pre_order_walk(|entry| {
let mut path = Utf8CStrBufArr::default();
entry.resolve_path(&mut path)?;
let path = path.as_utf8_cstr();
mount(
Some(path),
path,
None::<&Utf8CStr>,
MsFlags::MS_BIND | MsFlags::MS_RDONLY,
None::<&Utf8CStr>,
)
.check_os_err("occupy", Some(path), None)?;
Ok(Continue)
})
.log_ok();
})
.log_ok();
}
pub fn unoccupy(&self) -> bool {
let mut ok = false;
Directory::open(self)
.map(|mut dir| {
ok = dir
.pre_order_walk(|entry| {
let mut path = Utf8CStrBufArr::default();
entry.resolve_path(&mut path)?;
let path = path.as_utf8_cstr();
umount2(path, MntFlags::MNT_DETACH).check_os_err(
"unoccupy",
Some(path),
None,
)?;
if entry.is_dir() {
Ok(Skip)
} else {
Ok(Continue)
}
})
.is_ok();
})
.log_ok();
ok
}
}