Catch all errors when loading state file.

A crash during the multi-threaded import process may leave the pickled
state invalid (see #913). We recover from all these errors.
This commit is contained in:
Thomas Scholtes 2014-08-24 14:37:36 +02:00
parent 132fad847b
commit 225ce62a33
3 changed files with 12 additions and 1 deletions

View file

@ -65,7 +65,7 @@ def _open_state():
try:
with open(config['statefile'].as_filename()) as f:
return pickle.load(f)
except (IOError, EOFError):
except:
return {}

View file

@ -6,6 +6,10 @@ Changelog
This release adds **sorting** to beets queries. See :ref:`query-sort`.
Fixes:
* Invalid state files don't crash the importer.
1.3.7 (August 22, 2014)
-----------------------

View file

@ -1197,6 +1197,13 @@ class IncrementalImportTest(unittest.TestCase, TestHelper):
importer.run()
self.assertEqual(len(self.lib.items()), 2)
def test_invalid_state_file(self):
importer = self.create_importer()
with open(self.config['statefile'].as_filename(), 'w') as f:
f.write('000')
importer.run()
self.assertEqual(len(self.lib.albums()), 1)
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)