From b71f8eb5dd9a77aa6aae22d73c306cec72e7b644 Mon Sep 17 00:00:00 2001 From: Mahmoud Hashemi Date: Thu, 30 Jul 2015 23:34:42 -0700 Subject: [PATCH] proposed solution for #45 --- boltons/fileutils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/boltons/fileutils.py b/boltons/fileutils.py index 0e9bdc0..b23671e 100644 --- a/boltons/fileutils.py +++ b/boltons/fileutils.py @@ -265,8 +265,9 @@ class AtomicSaver(object): raise OSError(errno.EEXIST, 'Overwrite disabled and file already exists', self.dest_path) - _, tmp_part_path = tempfile.mkstemp(dir=self.dest_dir, - text=self.text_mode) + tmp_fd, tmp_part_path = tempfile.mkstemp(dir=self.dest_dir, + text=self.text_mode) + os.close(tmp_fd) try: _atomic_rename(tmp_part_path, self.part_path, overwrite=self.overwrite_part) @@ -282,6 +283,7 @@ class AtomicSaver(object): return self.part_file def __exit__(self, exc_type, exc_val, exc_tb): + self.part_file.close() if exc_type: if self.rm_part_on_exc: try: