read and write the pickled statefile as binary

Pickle files should be treated as binary files
This commit is contained in:
Johnny Robeson 2016-06-10 01:58:27 -04:00
parent ab67727283
commit a274b4e737
2 changed files with 4 additions and 4 deletions

View file

@ -69,7 +69,7 @@ class ImportAbort(Exception):
def _open_state():
"""Reads the state file, returning a dictionary."""
try:
with open(config['statefile'].as_filename()) as f:
with open(config['statefile'].as_filename(), 'rb') as f:
return pickle.load(f)
except Exception as exc:
# The `pickle` module can emit all sorts of exceptions during
@ -83,7 +83,7 @@ def _open_state():
def _save_state(state):
"""Writes the state dictionary out to disk."""
try:
with open(config['statefile'].as_filename(), 'w') as f:
with open(config['statefile'].as_filename(), 'wb') as f:
pickle.dump(state, f)
except IOError as exc:
log.error(u'state file could not be written: {0}', exc)

View file

@ -1341,8 +1341,8 @@ class IncrementalImportTest(unittest.TestCase, TestHelper):
def test_invalid_state_file(self):
importer = self.create_importer()
with open(self.config['statefile'].as_filename(), 'w') as f:
f.write('000')
with open(self.config['statefile'].as_filename(), 'wb') as f:
f.write(b'000')
importer.run()
self.assertEqual(len(self.lib.albums()), 1)