diff options
author | Scott D Phillips <scott.d.phillips@intel.com> | 2016-10-26 22:14:10 -0700 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-10-27 10:52:00 -0700 |
commit | ba578db0314aa85729ca13df734b2bd359d2aa35 (patch) | |
tree | 5b3a3d65d8001645c62ee7f6d54dc9f7978edeb4 /mesonbuild/mesonlib.py | |
parent | b05d37db67482af46f45636125d1513f18042029 (diff) | |
download | meson-ba578db0314aa85729ca13df734b2bd359d2aa35.zip meson-ba578db0314aa85729ca13df734b2bd359d2aa35.tar.gz meson-ba578db0314aa85729ca13df734b2bd359d2aa35.tar.bz2 |
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.
Diffstat (limited to 'mesonbuild/mesonlib.py')
-rw-r--r-- | mesonbuild/mesonlib.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 8133c48..943a23e 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): |