From 4e17077b5fd5096c8cdf64839b9dfa785bb70af0 Mon Sep 17 00:00:00 2001 From: David Howells Date: Thu, 15 May 2014 14:07:05 +0100 Subject: [PATCH] Add methods to evict entries from the PR ID<->Name cache 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 --- suite/commands/pts/adduser.py | 1 + suite/commands/pts/creategroup.py | 2 ++ suite/commands/pts/createuser.py | 3 +++ suite/commands/pts/delete.py | 2 ++ suite/commands/pts/removeuser.py | 1 + suite/commands/pts/rename.py | 2 ++ suite/lib/prcache.py | 32 +++++++++++++++++++++++++++++++ 7 files changed, 43 insertions(+) diff --git a/suite/commands/pts/adduser.py b/suite/commands/pts/adduser.py index cb82a8d..a8feb0c 100644 --- a/suite/commands/pts/adduser.py +++ b/suite/commands/pts/adduser.py @@ -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: diff --git a/suite/commands/pts/creategroup.py b/suite/commands/pts/creategroup.py index ae9aada..cf1e10e 100644 --- a/suite/commands/pts/creategroup.py +++ b/suite/commands/pts/creategroup.py @@ -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: diff --git a/suite/commands/pts/createuser.py b/suite/commands/pts/createuser.py index 065f65b..a0ff074 100644 --- a/suite/commands/pts/createuser.py +++ b/suite/commands/pts/createuser.py @@ -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: diff --git a/suite/commands/pts/delete.py b/suite/commands/pts/delete.py index c8859b7..3318341 100644 --- a/suite/commands/pts/delete.py +++ b/suite/commands/pts/delete.py @@ -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: diff --git a/suite/commands/pts/removeuser.py b/suite/commands/pts/removeuser.py index 204240f..cf03934 100644 --- a/suite/commands/pts/removeuser.py +++ b/suite/commands/pts/removeuser.py @@ -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: diff --git a/suite/commands/pts/rename.py b/suite/commands/pts/rename.py index 9c1d651..43b6b98 100644 --- a/suite/commands/pts/rename.py +++ b/suite/commands/pts/rename.py @@ -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") diff --git a/suite/lib/prcache.py b/suite/lib/prcache.py index da62e43..6a3b9cd 100644 --- a/suite/lib/prcache.py +++ b/suite/lib/prcache.py @@ -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() -- 2.49.0