diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-09-28 12:17:28 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-09-28 12:17:28 -0400 |
commit | a51d908d2fb08353c8aae349932c892d42f550c9 (patch) | |
tree | 655fda542d6e35e7ec0b3816a2c18ca33de8931d /src/lib | |
parent | 7c1553fac26fbfd4e59c06fd6a366e0dd817c517 (diff) | |
download | bcfg2-a51d908d2fb08353c8aae349932c892d42f550c9.tar.gz bcfg2-a51d908d2fb08353c8aae349932c892d42f550c9.tar.bz2 bcfg2-a51d908d2fb08353c8aae349932c892d42f550c9.zip |
POSIX: make sure to close file handles on temp files
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Bcfg2/Client/Tools/POSIX/File.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/lib/Bcfg2/Client/Tools/POSIX/File.py b/src/lib/Bcfg2/Client/Tools/POSIX/File.py index 40aade818..558d360b1 100644 --- a/src/lib/Bcfg2/Client/Tools/POSIX/File.py +++ b/src/lib/Bcfg2/Client/Tools/POSIX/File.py @@ -107,13 +107,16 @@ class POSIXFile(POSIXTool): (os.path.dirname(entry.get('name')), err)) return False try: - os.fdopen(newfd, 'w').write(filedata) - except (OSError, IOError): - err = sys.exc_info()[1] - self.logger.error("POSIX: Failed to open temp file %s for writing " - "%s: %s" % - (newfile, entry.get("name"), err)) - return False + try: + os.fdopen(newfd, 'w').write(filedata) + except (OSError, IOError): + err = sys.exc_info()[1] + self.logger.error("POSIX: Failed to open temp file %s for " + "writing %s: %s" % + (newfile, entry.get("name"), err)) + return False + finally: + os.close(newfd) return newfile def _rename_tmpfile(self, newfile, entry): |