[Freeipa-devel] [PATCH 4 of 7] Only update key/value files if necessary

Mark McLoughlin markmc at redhat.com
Thu Dec 13 09:35:06 UTC 2007


# HG changeset patch
# User Mark McLoughlin <markmc at redhat.com>
# Date 1197538288 0
# Node ID ad30235886a86e1ef06b65c50b0ed84df4ad6840
# Parent  cea59d38c4e7ac0e89e81d0f4bdea1d8bf61e760
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 at redhat.com>

diff -r cea59d38c4e7 -r ad30235886a8 ipa-server/ipaserver/krbinstance.py
--- a/ipa-server/ipaserver/krbinstance.py	Thu Dec 13 09:31:28 2007 +0000
+++ b/ipa-server/ipaserver/krbinstance.py	Thu Dec 13 09:31:28 2007 +0000
@@ -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):




More information about the Freeipa-devel mailing list