summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2007-12-13 09:31:28 +0000
committerMark McLoughlin <markmc@redhat.com>2007-12-13 09:31:28 +0000
commit7ba901d7774d914e1fc4aa06855f3f9f7ae6a7c4 (patch)
tree1b7e7686fed5066e775ef9edf6ad523a61f0b6e0
parent2a036abe7a601bbc8e65bbe4ab7c489b81db0eb5 (diff)
downloadfreeipa-7ba901d7774d914e1fc4aa06855f3f9f7ae6a7c4.tar.gz
freeipa-7ba901d7774d914e1fc4aa06855f3f9f7ae6a7c4.tar.xz
freeipa-7ba901d7774d914e1fc4aa06855f3f9f7ae6a7c4.zip
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 <markmc@redhat.com>
-rw-r--r--ipa-server/ipaserver/krbinstance.py8
1 files changed, 8 insertions, 0 deletions
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):