Skip to content

Commit 5183f1f

Browse files
Merge pull request mozilla#300 from adusca/issue299
Issue 299: Dealing better with corrupted files on Windows.
2 parents 658ed5a + bc1382c commit 5183f1f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

mozci/utils/transfer.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _load_json_file(filepath):
8686
LOG.debug("About to load %s." % filepath)
8787

8888
# Sniff whether the file is gzipped
89-
fd = open(filepath, 'r')
89+
fd = open(filepath, 'rb')
9090
magic = fd.read(2)
9191
fd.seek(0)
9292

@@ -99,7 +99,7 @@ def _load_json_file(filepath):
9999
LOG.debug("-> %s" % ' '.join(cmd))
100100
try:
101101
data = subprocess.check_output(cmd)
102-
except subprocess.CalledProcessError, e:
102+
except OSError, e:
103103
if e.errno == errno.ENOENT:
104104
raise Exception(
105105
"You don't have gzip installed on your system. "
@@ -135,7 +135,7 @@ def _save_file(req, filepath):
135135
size = int(req.headers['Content-Length'].strip())
136136
pbar = DownloadProgressBar(filepath, size).start()
137137
bytes = 0
138-
with open(filepath, 'w') as fd:
138+
with open(filepath, 'wb') as fd:
139139
for chunk in req.iter_content(10 * 1024):
140140
if chunk: # filter out keep-alive new chunks
141141
fd.write(chunk)
@@ -200,7 +200,7 @@ def load_file(filename, url):
200200
return _lean_load_json_file(filepath)
201201

202202
# Issue 213: sometimes we download a corrupted builds-*.js file
203-
except IOError:
203+
except (IOError, subprocess.CalledProcessError):
204204
LOG.info("%s is corrupted, we will have to download a new one.", filename)
205205
os.remove(filepath)
206206
return load_file(filename, url)
@@ -210,7 +210,7 @@ def _lean_load_json_file(filepath):
210210
"""Helper function to load json contents from a file using ijson."""
211211
LOG.debug("About to load %s." % filepath)
212212

213-
fd = open(filepath, 'r')
213+
fd = open(filepath, 'rb')
214214

215215
gzipper = gzip.GzipFile(fileobj=fd)
216216
builds = ijson.items(gzipper, 'builds.item')

0 commit comments

Comments
 (0)