More formatting/error message cleanups in storedPlaylist.c.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6265 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
J. Alexander Treuman 2007-05-26 00:48:53 +00:00
parent fd645486a1
commit f4d959a07b

View File

@ -34,15 +34,9 @@ static char *utf8pathToFsPathInStoredPlaylist(const char *utf8path, int fd)
char *actualFile; char *actualFile;
if (strstr(utf8path, "/")) { if (strstr(utf8path, "/")) {
if (fd != -1) { commandError(fd, ACK_ERROR_ARG, "playlist name \"%s\" is "
commandError(fd, ACK_ERROR_ARG, "playlist name \"%s\" " "invalid: playlist names may not contain slashes",
"is invalid: playlist names may not " utf8path);
"contain slashes", utf8path);
}
ERROR("playlist name \"%s\" is invalid: playlist names may not "
"contain slashes\n", utf8path);
return NULL; return NULL;
} }
@ -118,7 +112,6 @@ StoredPlaylist *newStoredPlaylist(const char *utf8name, int fd, int ignoreExisti
commandError(fd, ACK_ERROR_EXIST, commandError(fd, ACK_ERROR_EXIST,
"a file or directory already exists with " "a file or directory already exists with "
"the name \"%s\"", utf8name); "the name \"%s\"", utf8name);
free(sp); free(sp);
return NULL; return NULL;
} }
@ -152,31 +145,22 @@ StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd)
while (!(file = fopen(filename, "r")) && errno == EINTR); while (!(file = fopen(filename, "r")) && errno == EINTR);
if (file == NULL) { if (file == NULL) {
if (fd != -1) { commandError(fd, ACK_ERROR_NO_EXIST, "could not open file "
commandError(fd, ACK_ERROR_NO_EXIST, "\"%s\": %s", filename, strerror(errno));
"could not open file \"%s\": %s", filename,
strerror(errno));
}
ERROR("could not open file \"%s\": %s\n", filename,
strerror(errno));
return NULL; return NULL;
} }
sp = newStoredPlaylist(utf8path, fd, 1); sp = newStoredPlaylist(utf8path, fd, 1);
if (!sp) { if (!sp)
goto out; goto out;
}
while ((tempInt = fgetc(file)) != EOF) { while ((tempInt = fgetc(file)) != EOF) {
s[slength] = tempInt; s[slength] = tempInt;
if (s[slength] == '\n' || s[slength] == '\0') { if (s[slength] == '\n' || s[slength] == '\0') {
commentCharFound = 0; commentCharFound = 0;
s[slength] = '\0'; s[slength] = '\0';
if (s[0] == PLAYLIST_COMMENT) { if (s[0] == PLAYLIST_COMMENT)
commentCharFound = 1; commentCharFound = 1;
}
if (strncmp(s, musicDir, strlen(musicDir)) == 0) { if (strncmp(s, musicDir, strlen(musicDir)) == 0) {
strcpy(s, &(s[strlen(musicDir)])); strcpy(s, &(s[strlen(musicDir)]));
} else if (parentlen) { } else if (parentlen) {
@ -186,12 +170,9 @@ StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd)
strncat(s, "/", MAXPATHLEN - parentlen); strncat(s, "/", MAXPATHLEN - parentlen);
strncat(s, temp, MAXPATHLEN - parentlen - 1); strncat(s, temp, MAXPATHLEN - parentlen - 1);
if (strlen(s) >= MAXPATHLEN) { if (strlen(s) >= MAXPATHLEN) {
if (sp->fd != -1) { commandError(sp->fd,
commandError(sp->fd, ACK_ERROR_PLAYLIST_LOAD, ACK_ERROR_PLAYLIST_LOAD,
"\"%s\" is too long", temp); "\"%s\" is too long", temp);
}
ERROR("\"%s\" is too long\n", temp);
free(temp); free(temp);
freeStoredPlaylist(sp); freeStoredPlaylist(sp);
sp = NULL; sp = NULL;
@ -203,23 +184,19 @@ StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd)
temp = fsCharsetToUtf8(s); temp = fsCharsetToUtf8(s);
if (!temp) if (!temp)
continue; continue;
if (!commentCharFound) { if (!commentCharFound)
insertInListWithoutKey(sp->list, strdup(s)); insertInListWithoutKey(sp->list, strdup(s));
}
} else if (slength == MAXPATHLEN) { } else if (slength == MAXPATHLEN) {
s[slength] = '\0'; s[slength] = '\0';
if (sp->fd != -1) { commandError(sp->fd, ACK_ERROR_PLAYLIST_LOAD,
commandError(sp->fd, ACK_ERROR_PLAYLIST_LOAD, "line \"%s\" in playlist \"%s\" "
"line \"%s\" in playlist \"%s\" " "is too long", s, utf8path);
"is too long", s, utf8path);
}
ERROR("line \"%s\" in playlist \"%s\" is too long\n", s,
utf8path);
freeStoredPlaylist(sp); freeStoredPlaylist(sp);
sp = NULL; sp = NULL;
goto out; goto out;
} else if (s[slength] != '\r') } else if (s[slength] != '\r') {
slength++; slength++;
}
} }
out: out:
@ -396,14 +373,8 @@ static int writeStoredPlaylistToPath(StoredPlaylist *sp, const char *fspath)
while (!(file = fopen(fspath, "w")) && errno == EINTR); while (!(file = fopen(fspath, "w")) && errno == EINTR);
if (file == NULL) { if (file == NULL) {
if (sp->fd != -1) { commandError(sp->fd, ACK_ERROR_NO_EXIST, "could not open file "
commandError(sp->fd, ACK_ERROR_NO_EXIST, "\"%s\": %s", fspath, strerror(errno));
"could not open file \"%s\": %s", fspath,
strerror(errno));
}
ERROR("could not open file \"%s\": %s\n", fspath,
strerror(errno));
return -1; return -1;
} }
@ -486,7 +457,6 @@ int renameStoredPlaylist(int fd, const char *utf8from, const char *utf8to)
if (stat(from, &st) != 0) { if (stat(from, &st) != 0) {
commandError(fd, ACK_ERROR_NO_EXIST, commandError(fd, ACK_ERROR_NO_EXIST,
"no playlist named \"%s\"", utf8from); "no playlist named \"%s\"", utf8from);
ret = -1; ret = -1;
goto out; goto out;
} }
@ -494,7 +464,6 @@ int renameStoredPlaylist(int fd, const char *utf8from, const char *utf8to)
if (stat(to, &st) == 0) { if (stat(to, &st) == 0) {
commandError(fd, ACK_ERROR_EXIST, "a file or directory " commandError(fd, ACK_ERROR_EXIST, "a file or directory "
"already exists with the name \"%s\"", utf8to); "already exists with the name \"%s\"", utf8to);
ret = -1; ret = -1;
goto out; goto out;
} }
@ -503,7 +472,6 @@ int renameStoredPlaylist(int fd, const char *utf8from, const char *utf8to)
commandError(fd, ACK_ERROR_UNKNOWN, commandError(fd, ACK_ERROR_UNKNOWN,
"could not rename playlist \"%s\" to \"%s\": %s", "could not rename playlist \"%s\" to \"%s\": %s",
utf8from, utf8to, strerror(errno)); utf8from, utf8to, strerror(errno));
ret = -1; ret = -1;
goto out; goto out;
} }