diff --git a/NEWS b/NEWS index ecf574ea3..2a986a1fb 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,8 @@ * Fixed a spurious crash when LANG or a related environment variable is set to an invalid value (such as 'UTF-8' on some installations of Mac OS X). +* Fixed an error when trying to copy a file that is already at its + destination. 1.0b5 ----- diff --git a/beets/library.py b/beets/library.py index 67f41604a..684291a90 100644 --- a/beets/library.py +++ b/beets/library.py @@ -328,10 +328,11 @@ class Item(object): # Create necessary ancestry for the move. _mkdirall(dest) - if copy: - shutil.copy(self.path, dest) - else: - shutil.move(self.path, dest) + if not shutil._samefile(self.path, dest): + 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 diff --git a/test/test_files.py b/test/test_files.py index 6382062bb..7cc665054 100644 --- a/test/test_files.py +++ b/test/test_files.py @@ -72,6 +72,18 @@ class MoveTest(unittest.TestCase): def test_move_changes_path(self): self.i.move(self.lib) self.assertEqual(self.i.path, beets.library._normpath(self.dest)) + + def test_copy_already_at_destination(self): + self.i.move(self.lib) + old_path = self.i.path + self.i.move(self.lib, copy=True) + self.assertEqual(self.i.path, old_path) + + def test_move_already_at_destination(self): + self.i.move(self.lib) + old_path = self.i.path + self.i.move(self.lib, copy=False) + self.assertEqual(self.i.path, old_path) class HelperTest(unittest.TestCase): def test_ancestry_works_on_file(self):