remove rsmount dependency

This commit is contained in:
Mikaël Cluseau
2025-07-21 13:18:08 +02:00
parent b01c41b856
commit be5db231d9
4 changed files with 50 additions and 402 deletions

View File

@ -30,17 +30,14 @@ impl<'t> Dynlay<'t> {
}
let mount_path = PathBuf::from(lay_dir).join("mounts").join(layer);
let mount_path_str = mount_path.to_string_lossy().into_owned();
(fs::create_dir_all(&mount_path).await)
.map_err(|e| format_err!("mkdir -p {mount_path:?} failed: {e}"))?;
let mount_path = &fs::canonicalize(mount_path).await?;
let mount_path_str = &mount_path.to_string_lossy().into_owned();
let mut mount_info = rsmount::tables::MountInfo::new()?;
mount_info.import_mountinfo()?;
if mount_info.find_target(mount_path).is_some() {
if is_mount_point(mount_path_str).await? {
info!("clearing previous mount");
let mut paths = spawn_walk_dir(mount_path.clone());
@ -163,3 +160,29 @@ where
Err(format_err!("{program} failed: {status}"))
}
}
async fn is_mount_point(target: &str) -> Result<bool> {
for line in fs::read_to_string("/proc/self/mounts").await?.lines() {
let line = line.trim_ascii();
if line.is_empty() || line.starts_with("#") {
continue;
}
let split: Vec<_> = line.split_ascii_whitespace().collect();
if split.len() < 6 {
continue;
}
// let dev = split[0];
let mount_point = split[1];
// let fstype = split[2];
// let mntops = split[3];
// let fs_freq = split[4];
// let fsck_passno = split[5];
if mount_point == target {
return Ok(true);
}
}
Ok(false)
}