Skip to content

Commit

Permalink
ksud: fix clone symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
5ec1cff committed Nov 23, 2024
1 parent 89c7f1c commit 0bee77b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions userspace/ksud/src/magic_mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::cmp::PartialEq;
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::fs;
use std::fs::{create_dir, create_dir_all, read_dir, DirEntry, FileType};
use std::fs::{create_dir, create_dir_all, read_dir, read_link, DirEntry, FileType};
use std::os::unix::fs::{symlink, FileTypeExt};
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -171,8 +171,15 @@ fn collect_module_files() -> Result<Option<Node>> {
}

fn clone_symlink<Src: AsRef<Path>, Dst: AsRef<Path>>(src: Src, dst: Dst) -> Result<()> {
symlink(src.as_ref(), dst.as_ref())?;
let src_symlink = read_link(src.as_ref())?;
symlink(&src_symlink, dst.as_ref())?;
lsetfilecon(dst.as_ref(), lgetfilecon(src.as_ref())?.as_str())?;
log::debug!(
"clone symlink {} -> {}({})",
dst.as_ref().display(),
dst.as_ref().display(),
src_symlink.display()
);
Ok(())
}

Expand Down

0 comments on commit 0bee77b

Please sign in to comment.