From 6b113c8f6e71e8c5019bfdf07979cd3b8ce3a36e Mon Sep 17 00:00:00 2001 From: "adrian.sampson" Date: Wed, 25 Jun 2008 06:20:43 +0000 Subject: [PATCH] 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 --- beets/library.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/beets/library.py b/beets/library.py index 3d1dc9563..64b7d5b7a 100644 --- a/beets/library.py +++ b/beets/library.py @@ -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