Replace file.flush() calls with flush_sync() helper

Calls to `os.fsync(f.fileno())` need to be accompained by `f.flush()`.

Commit 8bbeedc93f introduces the helper
`ipapython.ipautil.flush_sync()`, which handles all calls in the right
order.

However, `flush_sync()` takes as parameter a file object with fileno
and name, where name must be a path to the file, this isn't possible
in some cases where file descriptors are used.

Issue: https://pagure.io/freeipa/issue/7251

Signed-off-by: Armando Neto <abiagion@redhat.com>
Reviewed-By: Christian Heimes <cheimes@redhat.com>
This commit is contained in:
Armando Neto
2018-07-05 15:12:33 -03:00
committed by Christian Heimes
parent f29412729e
commit b274da726b
5 changed files with 10 additions and 9 deletions

View File

@@ -1274,10 +1274,9 @@ def do_nsupdate(update_txt):
logger.debug("Writing nsupdate commands to %s:", UPDATE_FILE)
logger.debug("%s", update_txt)
update_fd = open(UPDATE_FILE, "w")
update_fd.write(update_txt)
update_fd.flush()
update_fd.close()
with open(UPDATE_FILE, "w") as f:
f.write(update_txt)
ipautil.flush_sync(f)
result = False
try: