mirror of
https://github.com/beetbox/beets.git
synced 2026-01-05 23:43:31 +01:00
consistency policy for DB mtimes (#227)
This commit is contained in:
parent
5111537cde
commit
b9d6928278
2 changed files with 37 additions and 1 deletions
|
|
@ -131,6 +131,7 @@ class Item(object):
|
|||
'album_id': None,
|
||||
})
|
||||
i.read(path)
|
||||
i.mtime = i.current_mtime() # Initial mtime.
|
||||
return i
|
||||
|
||||
def _fill_record(self, values):
|
||||
|
|
@ -177,10 +178,12 @@ class Item(object):
|
|||
value = str(value)
|
||||
|
||||
if key in ITEM_KEYS:
|
||||
# If the value changed, mark the field as dirty.
|
||||
if (not (key in self.record)) or (self.record[key] != value):
|
||||
# don't dirty if value unchanged
|
||||
self.record[key] = value
|
||||
self.dirty[key] = True
|
||||
if key in ITEM_KEYS_WRITABLE:
|
||||
self.mtime = 0 # Reset mtime on dirty.
|
||||
else:
|
||||
super(Item, self).__setattr__(key, value)
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import os
|
|||
import sqlite3
|
||||
import ntpath
|
||||
import posixpath
|
||||
import shutil
|
||||
|
||||
import _common
|
||||
from _common import item
|
||||
|
|
@ -653,6 +654,38 @@ class PathStringTest(unittest.TestCase):
|
|||
alb = self.lib.get_album(alb.id)
|
||||
self.assert_(isinstance(alb.artpath, str))
|
||||
|
||||
class MtimeTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.ipath = os.path.join(_common.RSRC, 'testfile.mp3')
|
||||
shutil.copy(os.path.join(_common.RSRC, 'full.mp3'), self.ipath)
|
||||
self.i = beets.library.Item.from_path(self.ipath)
|
||||
self.lib = beets.library.Library(':memory:')
|
||||
self.lib.add(self.i)
|
||||
|
||||
def tearDown(self):
|
||||
if os.path.exists(self.ipath):
|
||||
os.remove(self.ipath)
|
||||
|
||||
def _mtime(self):
|
||||
return os.path.getmtime(self.ipath)
|
||||
|
||||
def test_mtime_initially_up_to_date(self):
|
||||
self.assertGreaterEqual(self.i.mtime, self._mtime())
|
||||
|
||||
def test_mtime_reset_on_db_modify(self):
|
||||
self.i.title = 'something else'
|
||||
self.assertLess(self.i.mtime, self._mtime())
|
||||
|
||||
def test_mtime_up_to_date_after_write(self):
|
||||
self.i.title = 'something else'
|
||||
self.i.write()
|
||||
self.assertGreaterEqual(self.i.mtime, self._mtime())
|
||||
|
||||
def test_mtime_up_to_date_after_read(self):
|
||||
self.i.title = 'something else'
|
||||
self.i.read()
|
||||
self.assertGreaterEqual(self.i.mtime, self._mtime())
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue