Skip to content

Commit

Permalink
ksud: Copy directory permission mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tiann committed Mar 1, 2024
1 parent 2a4fa94 commit 8a59fe1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions userspace/ksud/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,19 @@ pub fn copy_module_files(source: impl AsRef<Path>, destination: impl AsRef<Path>
log::info!("Symlink: {:?} -> {:?}", dest_path, target);
std::os::unix::fs::symlink(target, &dest_path).context("Failed to create symlink")?;
copy_xattrs(&source_path, &dest_path)?;
let metadata =
std::fs::symlink_metadata(&dest_path).context("Failed to read metadata")?;
rustix::fs::chmodat(
rustix::fs::CWD,
&dest_path,
metadata.permissions().mode().into(),
rustix::fs::AtFlags::SYMLINK_NOFOLLOW,
)?;
} else if entry.file_type().is_dir() {
create_dir_all(&dest_path)?;
let metadata = std::fs::metadata(&source_path).context("Failed to read metadata")?;
std::fs::set_permissions(&dest_path, metadata.permissions())
.with_context(|| format!("Failed to set permissions for {dest_path:?}"))?;
copy_xattrs(&source_path, &dest_path)?;
} else if entry.file_type().is_char_device() {
if dest_path.exists() {
Expand Down

0 comments on commit 8a59fe1

Please sign in to comment.