mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-15 10:51:56 -06:00
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>
This commit is contained in:
parent
2a036abe7a
commit
7ba901d777
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user