From 31af7b3a02c00be3bc0b15f0a629e3322756ebfd Mon Sep 17 00:00:00 2001 From: kevinlondon Date: Sun, 20 Sep 2015 14:53:45 -0700 Subject: [PATCH 1/3] Replace mktemp with mkstemp --- letsencrypt/revoker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/letsencrypt/revoker.py b/letsencrypt/revoker.py index 239879542..036309b21 100644 --- a/letsencrypt/revoker.py +++ b/letsencrypt/revoker.py @@ -288,7 +288,7 @@ class Revoker(object): :class:`letsencrypt.revoker.Cert` """ - list_path2 = tempfile.mktemp(".tmp", "LIST") + _, list_path2 = tempfile.mkstemp(".tmp", "LIST") idx = 0 with open(self.list_path, "rb") as orgfile: From ff9f12aea606448a5705486c4630cca3a299defc Mon Sep 17 00:00:00 2001 From: kevinlondon Date: Mon, 21 Sep 2015 08:05:55 -0700 Subject: [PATCH 2/3] Use the file handle provided by mkstemp for opening the file. --- letsencrypt/revoker.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/letsencrypt/revoker.py b/letsencrypt/revoker.py index 036309b21..7fe1bd106 100644 --- a/letsencrypt/revoker.py +++ b/letsencrypt/revoker.py @@ -288,12 +288,12 @@ class Revoker(object): :class:`letsencrypt.revoker.Cert` """ - _, list_path2 = tempfile.mkstemp(".tmp", "LIST") + newfile_handle, list_path2 = tempfile.mkstemp(".tmp", "LIST") idx = 0 with open(self.list_path, "rb") as orgfile: csvreader = csv.reader(orgfile) - with open(list_path2, "wb") as newfile: + with os.fdopen(newfile_handle, "wb") as newfile: csvwriter = csv.writer(newfile) for row in csvreader: @@ -308,7 +308,7 @@ class Revoker(object): "Did not find all cert_list items to remove from LIST") shutil.copy2(list_path2, self.list_path) - os.remove(list_path2) + newfile.close() def _row_to_backup(self, row): """Convenience function From d4fa0363e320d7e68350eef20d952ef0074b5b88 Mon Sep 17 00:00:00 2001 From: kevinlondon Date: Mon, 21 Sep 2015 09:25:27 -0700 Subject: [PATCH 3/3] Removed the temp file again, not closing a closed file. --- letsencrypt/revoker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/letsencrypt/revoker.py b/letsencrypt/revoker.py index 7fe1bd106..32c6f003d 100644 --- a/letsencrypt/revoker.py +++ b/letsencrypt/revoker.py @@ -308,7 +308,7 @@ class Revoker(object): "Did not find all cert_list items to remove from LIST") shutil.copy2(list_path2, self.list_path) - newfile.close() + os.remove(list_path2) def _row_to_backup(self, row): """Convenience function