From 7ba901d7774d914e1fc4aa06855f3f9f7ae6a7c4 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Thu, 13 Dec 2007 09:31:28 +0000 Subject: Only update key/value files if necessary update_key_val_in_file() shouldn't try and write to a file if the key is already set to the given value in the file Rationale here is that if we write these files out while building a system image, ipa-server-install shouldn't need to re-write them and, therefore, they don't need to be writable. Signed-off-by: Mark McLoughlin --- ipa-server/ipaserver/krbinstance.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ipa-server/ipaserver/krbinstance.py b/ipa-server/ipaserver/krbinstance.py index c5ecbb892..5705a1ef3 100644 --- a/ipa-server/ipaserver/krbinstance.py +++ b/ipa-server/ipaserver/krbinstance.py @@ -58,6 +58,14 @@ def ldap_mod(fd, dn, pwd): def update_key_val_in_file(filename, key, val): if os.path.exists(filename): + pattern = "^[\s#]*%s\s*=\s*%s\s*" % (re.escape(key), re.escape(val)) + p = re.compile(pattern) + for line in fileinput.input(filename): + if p.search(line): + fileinput.close() + return + fileinput.close() + pattern = "^[\s#]*%s\s*=" % re.escape(key) p = re.compile(pattern) for line in fileinput.input(filename, inplace=1): -- cgit