From 0dac0f47269528a0e000c5c9beeddde4269f8a6c Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Mon, 23 Sep 2024 21:21:40 +0200 Subject: [PATCH] Implement update_acl_on_path() This allows to update or extend the existing ACL on path. Signed-off-by: Georg Pfuetzenreuter --- pyacl/acl.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pyacl/acl.py b/pyacl/acl.py index ca32bb6..3c35781 100644 --- a/pyacl/acl.py +++ b/pyacl/acl.py @@ -243,6 +243,26 @@ def apply_acl_to_path(acl, path): acl.applyto(path) +def update_acl_on_path(new_acl, path): + """ + Example usage: update_acl_on_path(posix1e.ACL, '/etc/foo.txt') + Return: None + """ + existing_acl = read_acl_from_path(path) + for entry in new_acl: + tag_type = entry.tag_type + if tag_type not in [ACL_USER_OBJ, ACL_GROUP_OBJ, ACL_OTHER, ACL_MASK]: + if tag_type in [ACL_USER, ACL_GROUP]: + for existing_entry in existing_acl: + if tag_type == existing_entry.tag_type: + if entry.qualifier == existing_entry.qualifier: + existing_acl.delete_entry(existing_entry) + existing_acl.append(entry) + + acl = existing_acl + return apply_acl_to_path(acl, path) + + def read_acl_from_path(path): """ Example usage: read_acl_from_path('/etc/foo.txt')