]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
Add methods to evict entries from the PR ID<->Name cache
authorDavid Howells <dhowells@redhat.com>
Thu, 15 May 2014 13:07:05 +0000 (14:07 +0100)
committerDavid Howells <dhowells@redhat.com>
Thu, 15 May 2014 13:07:05 +0000 (14:07 +0100)
Add methods to evict entries from the PR ID<->Name cache so that interactive
mode can make use of it.

Signed-off-by: David Howells <dhowells@redhat.com>
suite/commands/pts/adduser.py
suite/commands/pts/creategroup.py
suite/commands/pts/createuser.py
suite/commands/pts/delete.py
suite/commands/pts/removeuser.py
suite/commands/pts/rename.py
suite/lib/prcache.py

index cb82a8d39122d0c23a6b79c4a117ef5cb81c70a0..a8feb0c61ac2a45cb7087d1760c30ec0f59af8df 100644 (file)
@@ -80,6 +80,7 @@ def main(params):
 
             try:
                 ret = cell.call_pt_server(params, kafs.PR_AddToGroup, uid, gid)
+                prcache.evict_groups()
             except kafs.AbortPRIDEXIST:
                 error("Entry for id already exists ; unable to add user ", user, " to group ", group, ignored, "\n")
                 if "force" not in params:
index ae9aada7a8f9b5460e088ac39b91dcbc53781cca..cf1e10e47f24a3f35ae566403d15547218909309 100644 (file)
@@ -79,6 +79,8 @@ def main(params):
                 ret = cell.call_pt_server(params, kafs.PR_NewEntry, name, kafs.PRGRP, oid)
                 new_id = ret.id
             output("Group ", name, " has id ", new_id, "\n")
+            evict_name(name)
+            evict_id(new_id)
         except kafs.AbortPREXIST:
             error("Entry for name already exists ; unable to create group ", name, "\n")
             if "force" not in params:
index 065f65b11c70176844b59de23d6b216f24ad346f..a0ff0741cbe0a07b7e679fc770b59a61d6158d82 100644 (file)
@@ -55,6 +55,7 @@ Create a user or machine entry in the Protection Database
 def main(params):
     exitcode = 0
     cell = params["cell"]
+    prcache = cell.get_prcache(params)
 
     names = params["name"]
     if "id" in params:
@@ -72,6 +73,8 @@ def main(params):
                 ret = cell.call_pt_server(params, kafs.PR_INewEntry, name, 0, 0)
                 new_id = ret.id
             output("User ", name, " has id ", new_id, "\n")
+            evict_name(name)
+            evict_id(new_id)
         except kafs.AbortPREXIST:
             error("Entry for name already exists ; unable to create user ", name, "\n")
             if "force" not in params:
index c8859b79b7dcd5b78506966750d9ea050364d761..33183413b13221533f363bc51dd747ef114eaec4 100644 (file)
@@ -69,6 +69,8 @@ def main(params):
         try:
             verbose("Deleting user ", uid, " (", prcache.id_to_name(uid), ")\n")
             ret = cell.call_pt_server(params, kafs.PR_Delete, uid)
+            prcache.evict_id(uid)
+            prcache.evict_groups()
         except kafs.AbortPRNOENT:
             error("User or group doesn't exist deleting ", name, " (id ", uid, ")\n")
             if "force" not in params:
index 204240f4eddd01f7cbe826480134017de41758ad..cf0393427c10f57815c4cb2e278f5010bc73ca6f 100644 (file)
@@ -80,6 +80,7 @@ def main(params):
 
             try:
                 ret = cell.call_pt_server(params, kafs.PR_RemoveFromGroup, uid, gid)
+                prcache.evict_groups()
             except kafs.AbortPRNOENT:
                 error("User or group doesn't exist ; unable to remove user ", user, " from group ", group, ignored, "\n")
                 if "force" not in params:
index 9c1d65143dcc0453a77e463741f3863103c5f34b..43b6b98f0ea2cfaa4d39fd0ed0446f0b655f3268 100644 (file)
@@ -68,6 +68,8 @@ def main(params):
     try:
         verbose("Renaming ", uid, " to ", newname, "\n")
         ret = cell.call_pt_server(params, kafs.PR_ChangeEntry, uid, newname, 0, 0)
+        prcache.evict_id(uid)
+        prcache.evict_groups()
     except kafs.AbortPREXIST:
         error("Entry for name already exists ; unable to change name of ",
               prcache.id_to_name(uid), " to ", newname, "\n")
index da62e4376755c915ada327f376257d8d628f8d0c..6a3b9cd98af6c656d19799004111fed2541a9991 100644 (file)
@@ -226,6 +226,30 @@ class prcache:
             entry = AFS_PR_Entry(name, None)
             self.__name2id[name] = entry
 
+    ###########################################################################
+    #
+    # Evict a name and the corresponding ID from the cache
+    #
+    ###########################################################################
+    def evict_name(self, name):
+        if name in self.__name2id:
+            ugid = self.__name2id[name].ugid()
+            del self.__name2id[name]
+            if ugid != None:
+                del self.__id2name[ugid]
+
+    ###########################################################################
+    #
+    # Evict an id and the corresponding name from the cache
+    #
+    ###########################################################################
+    def evict_id(self, ugid):
+        if ugid in self.__id2name:
+            name = self.__id2name[ugid].name()
+            del self.__id2name[ugid]
+            if name != None:
+                del self.__name2id[name]
+
     ###########################################################################
     #
     # Note that an ID is unknown
@@ -292,3 +316,11 @@ class prcache:
         assert(gid < 0)
         group = self.__groups[gid]
         return group.expand(self)
+
+    ###########################################################################
+    #
+    # Evict all group records from the group cache
+    #
+    ###########################################################################
+    def evict_groups(self):
+        self.__groups = dict()