diff options
| author | Robert C Jennings <robert.jennings@canonical.com> | 2017-06-26 16:26:03 -0500 | 
|---|---|---|
| committer | Robert C Jennings <robert.jennings@canonical.com> | 2017-06-26 16:26:03 -0500 | 
| commit | 399c17c3668ca6f8339cd39f24b35c663bc5e335 (patch) | |
| tree | a46fa10d043ef97ca28545e3f137db1cf65c2f56 | |
| parent | ef63e053cdb1cc7981bf766e63d96a49fdde37dd (diff) | |
Use a real temporary file
bzr-revno: 18.2.21
| -rwxr-xr-x | mfdiff | 18 | 
1 files changed, 10 insertions, 8 deletions
| @@ -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))) | 
