Compare commits

..

1 Commits

Author SHA1 Message Date
0dac0f4726
Implement update_acl_on_path()
This allows to update or extend the existing ACL on path.

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2024-09-23 21:21:40 +02:00

View File

@ -248,22 +248,18 @@ def update_acl_on_path(new_acl, path):
Example usage: update_acl_on_path(posix1e.ACL, '/etc/foo.txt')
Return: None
"""
acl = read_acl_from_path(path)
existing_acl = read_acl_from_path(path)
for entry in new_acl:
tag_type = entry.tag_type
# keep existing entries which may only exist once
if tag_type not in [ACL_USER_OBJ, ACL_GROUP_OBJ, ACL_OTHER, ACL_MASK]:
# replace existing user/group entries with new ones if the uid/gid matches
if tag_type in [ACL_USER, ACL_GROUP]:
for existing_entry in acl:
for existing_entry in existing_acl:
if tag_type == existing_entry.tag_type:
if entry.qualifier == existing_entry.qualifier:
acl.delete_entry(existing_entry)
acl.append(entry)
existing_acl.delete_entry(existing_entry)
existing_acl.append(entry)
acl = existing_acl
return apply_acl_to_path(acl, path)