playlist: don't allow no-op/senseless movement of songs

This disables moving the bonkered moving of the current song to
a (negative) offset of itself (introduced in the last commit).

This also short circuits no-op moves when (from == to) and
avoid needless increasing of the playlist version and causes
clients to issue pointless no-op plchanges commands.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7153 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Eric Wong 2008-01-26 12:47:04 +00:00
parent e213ca4f8b
commit 3a1b3e3807

View File

@ -1144,8 +1144,7 @@ int moveSongInPlaylist(int fd, int from, int to)
int i;
Song *tmpSong;
int tmpId;
int queuedSong = -1;
int currentSong = -1;
int currentSong;
if (from < 0 || from >= playlist.length) {
commandError(fd, ACK_ERROR_NO_EXIST,
@ -1160,19 +1159,26 @@ int moveSongInPlaylist(int fd, int from, int to)
return -1;
}
if (from == to) /* no-op */
return 0;
/*
* (to < 0) => move to offset from current song
* (-playlist.length == to) => move to position BEFORE current song
*/
if (to < 0 && playlist.current >= 0)
to = (playlist.order[playlist.current] + abs(to)) %
playlist.length;
currentSong = playlist.order[playlist.current];
if (to < 0 && playlist.current >= 0) {
if (currentSong == from)
/* no-op, can't be moved to offset of itself */
return 0;
to = (currentSong + abs(to)) % playlist.length;
}
if (playlist_state == PLAYLIST_STATE_PLAY) {
if (playlist.queued >= 0) {
int queuedSong = -1;
if (playlist.queued >= 0)
queuedSong = playlist.order[playlist.queued];
}
currentSong = playlist.order[playlist.current];
if (queuedSong == from || queuedSong == to
|| currentSong == from || currentSong == to) {
lockPlaylistInteraction();