From ba578db0314aa85729ca13df734b2bd359d2aa35 Mon Sep 17 00:00:00 2001 From: Scott D Phillips Date: Wed, 26 Oct 2016 22:14:10 -0700 Subject: mesonlib: close file before (re)moving On windows, attempting to unlink an open file results in a PermissionError, so close the file and then remove it. --- mesonbuild/mesonlib.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 8133c487b..943a23e08 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -320,14 +320,17 @@ def dump_conf_header(ofilename, cdata): def replace_if_different(dst, dst_tmp): # If contents are identical, don't touch the file to prevent # unnecessary rebuilds. + different = True try: with open(dst, 'r') as f1, open(dst_tmp, 'r') as f2: if f1.read() == f2.read(): - os.unlink(dst_tmp) - return + different = False except FileNotFoundError: pass - os.replace(dst_tmp, dst) + if different: + os.replace(dst_tmp, dst) + else: + os.unlink(dst_tmp) def stringlistify(item): if isinstance(item, str): -- cgit v1.2.3