summaryrefslogtreecommitdiff
diff options
authorRobert C Jennings <robert.jennings@canonical.com>2017-06-26 16:26:03 -0500
committerRobert C Jennings <robert.jennings@canonical.com>2017-06-26 16:26:03 -0500
commit399c17c3668ca6f8339cd39f24b35c663bc5e335 (patch)
treea46fa10d043ef97ca28545e3f137db1cf65c2f56
parentef63e053cdb1cc7981bf766e63d96a49fdde37dd (diff)
Use a real temporary file
bzr-revno: 18.2.21
-rwxr-xr-xmfdiff18
1 files changed, 10 insertions, 8 deletions
diff --git a/mfdiff b/mfdiff
index a6787cc..42c81ba 100755
--- a/mfdiff
+++ b/mfdiff
@@ -30,6 +30,7 @@ import os
import os.path
import re
import sys
+import tempfile
from optparse import OptionParser
import apt
@@ -97,7 +98,9 @@ def get_changelog(source, version, changelog_cache_d):
furls = []
num_colon_m = re.compile("[0-9]:")
- cache_tmp = "%s/.changelog.%s_%s" % (changelog_cache_d, source, version)
+ cache_tmp_fd, cache_tmp_path = tempfile.mkstemp(".changelog.%s_%s"
+ % (source, version))
+ cache_tmp = os.fdopen(cache_tmp_fd, "w")
for pile in ("main", "universe", "multiverse", "restricted"):
pre = source[0:1]
# packages starting with 'lib' are special
@@ -120,16 +123,15 @@ def get_changelog(source, version, changelog_cache_d):
changelog = requests.get(clog_url)
if changelog.status_code == 200:
- logging.debug("Found changelog for %s in %s", source, pile)
- with open(cache_tmp, "w") as cache_file:
- cache_file.write(changelog.content)
- os.rename(cache_tmp, cache_f)
- return cache_f
+ cache_tmp.write(changelog.content)
+ cache_tmp.close()
+ os.rename(cache_tmp_path, cache_f)
+ return cache_f
else:
logging.error("missing %s: %s", source, clog_url)
furls.append(clog_url)
- if os.path.exists(cache_tmp):
- os.unlink(cache_tmp)
+ if os.path.exists(cache_tmp_path):
+ os.unlink(cache_tmp_path)
raise MissingChangelogError("Failed to find changelog for %s at version "
"%s.\n tried %s" % (source, version,
' '.join(furls)))