mirror of
https://github.com/beetbox/beets.git
synced 2026-01-27 02:23:36 +01:00
allow "null" album art setting (when it's already in place)
This commit is contained in:
parent
f3130152b1
commit
f54ace110c
2 changed files with 42 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue