diff options
author | J. Alexander Treuman <jat@spatialrift.net> | 2007-05-24 18:07:19 +0000 |
---|---|---|
committer | J. Alexander Treuman <jat@spatialrift.net> | 2007-05-24 18:07:19 +0000 |
commit | 7ba357a04e75c51f898e9418cab24d10c74ab37c (patch) | |
tree | a607055f440379beb1ea54dc6eb116a796c39ed9 /src/storedPlaylist.c | |
parent | 0d7d2ebf80be04864eff70369d7aa88a5670806a (diff) | |
download | mpd-7ba357a04e75c51f898e9418cab24d10c74ab37c.tar.gz mpd-7ba357a04e75c51f898e9418cab24d10c74ab37c.tar.xz mpd-7ba357a04e75c51f898e9418cab24d10c74ab37c.zip |
Adding rename command, for renaming stored playlists.
git-svn-id: https://svn.musicpd.org/mpd/trunk@6246 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/storedPlaylist.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/storedPlaylist.c b/src/storedPlaylist.c index 8bec60e71..3559d1e2f 100644 --- a/src/storedPlaylist.c +++ b/src/storedPlaylist.c @@ -489,3 +489,68 @@ void appendPlaylistToStoredPlaylist(StoredPlaylist *sp, Playlist *playlist) appendSongToStoredPlaylist(sp, playlist->songs[i]); } } + +int renameStoredPlaylist(int fd, const char *utf8from, const char *utf8to) +{ + struct stat st; + char *from; + char *to; + int ret = 0; + + from = xstrdup(utf8pathToFsPathInStoredPlaylist(utf8from, fd)); + if (!from) + return -1; + + to = xstrdup(utf8pathToFsPathInStoredPlaylist(utf8to, fd)); + if (!to) { + free(from); + return -1; + } + + if (stat(from, &st) != 0) { + if (fd != -1) { + commandError(fd, ACK_ERROR_NO_EXIST, + "no playlist named \"%s\"", utf8from); + } + + ERROR("no playlist named \"%s\"\n", utf8from); + + ret = -1; + goto out; + } + + if (stat(to, &st) == 0) { + if (fd != -1) { + commandError(fd, ACK_ERROR_EXIST, "a file or directory " + "already exists with the name \"%s\"", + utf8to); + } + + ERROR("a file or directory already exists with the " + "name \"%s\"\n", utf8to); + + ret = -1; + goto out; + } + + if (rename(from, to) < 0) { + if (fd != -1) { + commandError(fd, ACK_ERROR_UNKNOWN, + "could not rename playlist \"%s\" to " + "\"%s\": %s", utf8from, utf8to, + strerror(errno)); + } + + ERROR("could not rename playlist \"%s\" to \"%s\": %s\n", + utf8from, utf8to, strerror(errno)); + + ret = -1; + goto out; + } + +out: + free(from); + free(to); + + return ret; +} |