summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-28 12:17:28 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-28 12:17:28 -0400
commita51d908d2fb08353c8aae349932c892d42f550c9 (patch)
tree655fda542d6e35e7ec0b3816a2c18ca33de8931d /src/lib
parent7c1553fac26fbfd4e59c06fd6a366e0dd817c517 (diff)
downloadbcfg2-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.py17
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):