aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-09-29 13:17:52 +0200
committerMax Kellermann <max@duempel.org>2008-09-29 13:17:52 +0200
commitda79498afdf649cb0c41a1bb25e6b1dbe2909d35 (patch)
tree4ab502e18f528a678940a93323af8781b643434d /src
parent4e15e292e04084ed534e2322efe8e0d81ada9557 (diff)
downloadmpd-da79498afdf649cb0c41a1bb25e6b1dbe2909d35.tar.gz
mpd-da79498afdf649cb0c41a1bb25e6b1dbe2909d35.tar.xz
mpd-da79498afdf649cb0c41a1bb25e6b1dbe2909d35.zip
directory: writeDirectoryInfo propagates errors
If a write failed, it's a good sign subsequent writes will fail, too, so propgate errors all the way up the stack.
Diffstat (limited to 'src')
-rw-r--r--src/directory.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/directory.c b/src/directory.c
index 158a63d3d..9b18db4d6 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -692,7 +692,7 @@ int printDirectoryInfo(struct client *client, const char *name)
}
/* TODO error checking */
-static void writeDirectoryInfo(FILE * fp, Directory * directory)
+static int writeDirectoryInfo(FILE * fp, Directory * directory)
{
struct dirvec *children = &directory->children;
size_t i;
@@ -700,11 +700,9 @@ static void writeDirectoryInfo(FILE * fp, Directory * directory)
if (directory->path) {
retv = fprintf(fp, "%s%s\n", DIRECTORY_BEGIN,
- getDirectoryPath(directory));
- if (retv < 0) {
- ERROR("Failed to write data to database file: %s\n",strerror(errno));
- return;
- }
+ getDirectoryPath(directory));
+ if (retv < 0)
+ return -1;
}
for (i = 0; i < children->nr; ++i) {
@@ -712,24 +710,19 @@ static void writeDirectoryInfo(FILE * fp, Directory * directory)
const char *base = mpd_basename(cur->path);
retv = fprintf(fp, DIRECTORY_DIR "%s\n", base);
- if (retv < 0) {
- ERROR("Failed to write data to database file: %s\n",
- strerror(errno));
- return;
- }
- writeDirectoryInfo(fp, cur);
+ if (retv < 0)
+ return -1;
+ if (writeDirectoryInfo(fp, cur) < 0)
+ return -1;
}
songvec_save(fp, &directory->songs);
- if (directory->path) {
- retv = fprintf(fp, "%s%s\n", DIRECTORY_END,
- getDirectoryPath(directory));
- if (retv < 0) {
- ERROR("Failed to write data to database file: %s\n",strerror(errno));
- return;
- }
- }
+ if (directory->path &&
+ fprintf(fp, DIRECTORY_END "%s\n",
+ getDirectoryPath(directory)) < 0)
+ return -1;
+ return 0;
}
static void readDirectoryInfo(FILE * fp, Directory * directory)
@@ -865,7 +858,12 @@ int writeDirectoryDB(void)
fprintf(fp, "%s%s\n", DIRECTORY_FS_CHARSET, getFsCharset());
fprintf(fp, "%s\n", DIRECTORY_INFO_END);
- writeDirectoryInfo(fp, music_root);
+ if (writeDirectoryInfo(fp, music_root) < 0) {
+ ERROR("Failed to write to database file: %s\n",
+ strerror(errno));
+ while (fclose(fp) && errno == EINTR);
+ return -1;
+ }
while (fclose(fp) && errno == EINTR);