mirror of
https://github.com/beetbox/beets.git
synced 2025-12-28 19:42:42 +01:00
move() now has less confusing behavior, unambiguously moving (even across FS boundaries) or copying
--HG-- extra : convert_revision : svn%3A41726ec3-264d-0410-9c23-a9f1637257cc/trunk%4023
This commit is contained in:
parent
e469f308e1
commit
6b113c8f6e
1 changed files with 8 additions and 12 deletions
|
|
@ -249,15 +249,14 @@ class Item(object):
|
|||
|
||||
def move(self, copy=False):
|
||||
"""Move the item to its designated location within the library
|
||||
directory. Subdirectories are created as needed. If moving fails (for
|
||||
instance, because the move would cross filesystems), a copy is
|
||||
attempted. If moving or copying succeeds, the path in the database is
|
||||
updated to reflect the new location.
|
||||
directory (provided by destination()). Subdirectories are created as
|
||||
needed. If the operation succeeds, the path in the database is updated
|
||||
to reflect the new location.
|
||||
|
||||
If copy is True, moving is not attempted before copying.
|
||||
If copy is True, moving the file is copied rather than moved.
|
||||
|
||||
Passes on appropriate exceptions if directories cannot be created or
|
||||
copying fails.
|
||||
moving/copying fails.
|
||||
|
||||
Note that one should almost certainly call library.save() after this
|
||||
method in order to keep on-disk data consistent."""
|
||||
|
|
@ -272,13 +271,10 @@ class Item(object):
|
|||
if not os.path.isdir(ancestor):
|
||||
os.mkdir(ancestor)
|
||||
|
||||
try: # move
|
||||
if copy:
|
||||
# Hacky. Skip to "except" so we don't try moving.
|
||||
raise Exception('skipping move')
|
||||
os.rename(self.path, dest)
|
||||
except: # copy
|
||||
if copy:
|
||||
shutil.copy(self.path, dest)
|
||||
else:
|
||||
shutil.move(self.path, dest)
|
||||
|
||||
# Either copying or moving succeeded, so update the stored path.
|
||||
self.path = dest
|
||||
|
|
|
|||
Loading…
Reference in a new issue