ACLEditor/src/helper/acl_writer.rs
2024-08-18 15:41:31 +02:00

25 lines
623 B
Rust

use std::path::Path;
use anyhow::Result;
use posix_acl::PosixACL;
use walkdir::WalkDir;
pub fn write_acl_recursive<P: AsRef<Path>>(path: P, acl: PosixACL) -> Result<()> {
for entry in WalkDir::new(path).min_depth(0).follow_links(false) {
let entry = entry?;
let path = entry.path();
println!("Writing ACL for: {:?} {:?}", path, acl);
match entry.file_type().is_dir() {
true => {
acl.write(&path)?;
acl.write_default(&path)?;
}
false => {
acl.write(&path)?;
}
}
}
Ok(())
}