From 5d3796b4044fa8da7eaab22bb337cc4385e67221 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Thu, 15 Sep 2011 16:22:47 -0700 Subject: [PATCH] further move() refactoring: file manipulation on Item --- beets/library.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/beets/library.py b/beets/library.py index 2d1c1d0cc..31f9946f5 100644 --- a/beets/library.py +++ b/beets/library.py @@ -209,6 +209,21 @@ class Item(object): f.save() + # Files themselves. + + def move(self, dest, copy=False): + """Moves or copies the item's file, updating the path value if + the move succeeds. + """ + if copy: + util.copy(self.path, dest) + else: + util.move(self.path, dest) + + # Either copying or moving succeeded, so update the stored path. + self.path = dest + + # Library queries. class Query(object): @@ -946,14 +961,9 @@ class Library(BaseLibrary): # Create necessary ancestry for the move. util.mkdirall(dest) - if copy: - util.copy(item.path, dest) - else: - util.move(item.path, dest) - - # Either copying or moving succeeded, so update the stored path. + # Perform the move. old_path = item.path - item.path = dest + item.move(dest, copy) # Prune vacated directory. if not copy: