final refactoring: lib.move() now affects DB

This commit is contained in:
Adrian Sampson 2011-09-15 16:38:36 -07:00
parent 5d3796b404
commit c67f88bccb

View file

@ -952,18 +952,21 @@ class Library(BaseLibrary):
Passes on appropriate exceptions if directories cannot be
created or moving/copying fails.
Note that one should almost certainly call store() and
library.save() after this method in order to keep on-disk data
consistent.
The item is stored to the database if it is in the database, so
any dirty fields prior to the move() call will be written as a
side effect. You probably want to call save() to commit the DB
transaction.
"""
dest = self.destination(item, in_album=in_album, basedir=basedir)
# Create necessary ancestry for the move.
util.mkdirall(dest)
# Perform the move.
# Perform the move and store the change.
old_path = item.path
item.move(dest, copy)
if item.id is not None:
self.store(item)
# Prune vacated directory.
if not copy:
@ -1189,11 +1192,6 @@ class Album(BaseAlbum):
util.prune_dirs(os.path.dirname(old_art),
self._library.directory)
# Store new item paths. We do this at the end to avoid
# locking the database for too long while files are copied.
for item in items:
self._library.store(item)
def item_dir(self):
"""Returns the directory containing the album's first item,
provided that such an item exists.