implement basic ordering. This might still be wrong!!
This commit is contained in:
parent
d1ef6513ce
commit
dfad5cc74c
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -31,7 +31,7 @@ checksum = "a5f43f184355eefb8d17fc948dbecf6c13be3c141f20d834ae842193a448c72a"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "posix-acl"
|
name = "posix-acl"
|
||||||
version = "0.1.1"
|
version = "0.1.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"acl-sys",
|
"acl-sys",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "posix-acl"
|
name = "posix-acl"
|
||||||
version = "0.1.1"
|
version = "0.1.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
24
src/lib.rs
24
src/lib.rs
@ -35,22 +35,22 @@ pub static ACL_NONE: PermSet = PermSet::empty();
|
|||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum Qualifier {
|
pub enum Qualifier {
|
||||||
UserObj,
|
UserObj,
|
||||||
GroupObj,
|
|
||||||
Other,
|
|
||||||
User(u32),
|
User(u32),
|
||||||
|
GroupObj,
|
||||||
Group(u32),
|
Group(u32),
|
||||||
Mask,
|
Mask,
|
||||||
|
Other,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Qualifier {
|
impl Qualifier {
|
||||||
pub fn get_tag(&self) -> i32 {
|
pub fn get_tag(&self) -> i32 {
|
||||||
match self {
|
match self {
|
||||||
Qualifier::UserObj => ACL_USER_OBJ,
|
Qualifier::UserObj => ACL_USER_OBJ,
|
||||||
Qualifier::GroupObj => ACL_GROUP_OBJ,
|
|
||||||
Qualifier::Other => ACL_OTHER,
|
|
||||||
Qualifier::User(_) => ACL_USER,
|
Qualifier::User(_) => ACL_USER,
|
||||||
|
Qualifier::GroupObj => ACL_GROUP_OBJ,
|
||||||
Qualifier::Group(_) => ACL_GROUP,
|
Qualifier::Group(_) => ACL_GROUP,
|
||||||
Qualifier::Mask => ACL_MASK,
|
Qualifier::Mask => ACL_MASK,
|
||||||
|
Qualifier::Other => ACL_OTHER,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,10 +63,16 @@ impl Qualifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, PartialEq, Eq, Ord)]
|
||||||
pub struct ACLEntry(pub Qualifier, pub PermSet);
|
pub struct ACLEntry(pub Qualifier, pub PermSet);
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
impl PartialOrd for ACLEntry {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
|
Some(self.0.cmp(&other.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd)]
|
||||||
pub struct PosixACL {
|
pub struct PosixACL {
|
||||||
pub entries: Vec<ACLEntry>,
|
pub entries: Vec<ACLEntry>,
|
||||||
}
|
}
|
||||||
@ -201,6 +207,7 @@ impl PosixACL {
|
|||||||
pub fn write<P: AsRef<Path>>(&self, path: P) -> Result<()> {
|
pub fn write<P: AsRef<Path>>(&self, path: P) -> Result<()> {
|
||||||
// Write ACL to file
|
// Write ACL to file
|
||||||
self.write_type(path, ACL_TYPE_ACCESS)?;
|
self.write_type(path, ACL_TYPE_ACCESS)?;
|
||||||
|
// TODO: If necessary fix mask
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,8 +340,11 @@ mod test {
|
|||||||
file.write_all(b"Hello, world!").unwrap();
|
file.write_all(b"Hello, world!").unwrap();
|
||||||
|
|
||||||
acl.write(path).unwrap();
|
acl.write(path).unwrap();
|
||||||
|
acl.entries.sort();
|
||||||
|
|
||||||
|
let mut acl_r = PosixACL::new_from_file(path, false).unwrap();
|
||||||
|
acl_r.entries.sort();
|
||||||
|
|
||||||
let acl_r = PosixACL::new_from_file(path, false).unwrap();
|
|
||||||
println!("{:?}", acl);
|
println!("{:?}", acl);
|
||||||
assert_eq!(acl.entries.len(), acl_r.entries.len());
|
assert_eq!(acl.entries.len(), acl_r.entries.len());
|
||||||
let missing = acl
|
let missing = acl
|
||||||
|
Loading…
Reference in New Issue
Block a user