mirror of
https://github.com/beetbox/beets.git
synced 2026-02-23 07:44:38 +01:00
read and write the pickled statefile as binary
Pickle files should be treated as binary files
This commit is contained in:
parent
ab67727283
commit
a274b4e737
2 changed files with 4 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue