diff --git a/beets/library.py b/beets/library.py index 0ff5d964e..01fd7c1fb 100644 --- a/beets/library.py +++ b/beets/library.py @@ -1212,8 +1212,17 @@ class Album(BaseAlbum): path = bytestring_path(path) oldart = self.artpath artdest = self.art_destination(path) + + if oldart and shutil._samefile(syspath(path), syspath(oldart)): + # Art already set. + return + elif shutil._samefile(syspath(path), syspath(artdest)): + # Art already in place. + self.artpath = path + return + + # Normal operation. if oldart == artdest: util.soft_remove(oldart) - shutil.copyfile(syspath(path), syspath(artdest)) self.artpath = artdest diff --git a/test/test_files.py b/test/test_files.py index 5d3ff3b56..7c28944ad 100644 --- a/test/test_files.py +++ b/test/test_files.py @@ -228,6 +228,38 @@ class ArtFileTest(unittest.TestCase): ai.set_art(newart) self.assertTrue(os.path.exists(ai.artpath)) + def test_setart_to_existing_art_works(self): + # Original art. + newart = os.path.join(self.libdir, 'newart.jpg') + touch(newart) + i2 = item() + i2.path = self.i.path + i2.artist = 'someArtist' + ai = self.lib.add_album((i2,)) + i2.move(self.lib, True) + ai.set_art(newart) + + # Set the art again. + ai.set_art(ai.artpath) + self.assertTrue(os.path.exists(ai.artpath)) + + def test_setart_to_existing_but_unset_art_works(self): + newart = os.path.join(self.libdir, 'newart.jpg') + touch(newart) + i2 = item() + i2.path = self.i.path + i2.artist = 'someArtist' + ai = self.lib.add_album((i2,)) + i2.move(self.lib, True) + + # Copy the art to the destination. + artdest = ai.art_destination(newart) + shutil.copy(newart, artdest) + + # Set the art again. + ai.set_art(artdest) + self.assertTrue(os.path.exists(ai.artpath)) + def test_setart_sets_permissions(self): newart = os.path.join(self.libdir, 'newart.jpg') touch(newart)