From 3a1b3e3807609434bf3f392b6b1f66ac218e265c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 26 Jan 2008 12:47:04 +0000 Subject: 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 --- src/playlist.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/playlist.c b/src/playlist.c index a2dfd0602..0f76c49a0 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -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(); -- cgit v1.2.3