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.
This commit is contained in:
Eric Wong 2008-09-29 13:17:52 +02:00 committed by Max Kellermann
parent 4e15e292e0
commit da79498afd

View File

@ -692,7 +692,7 @@ int printDirectoryInfo(struct client *client, const char *name)
} }
/* TODO error checking */ /* TODO error checking */
static void writeDirectoryInfo(FILE * fp, Directory * directory) static int writeDirectoryInfo(FILE * fp, Directory * directory)
{ {
struct dirvec *children = &directory->children; struct dirvec *children = &directory->children;
size_t i; size_t i;
@ -700,11 +700,9 @@ static void writeDirectoryInfo(FILE * fp, Directory * directory)
if (directory->path) { if (directory->path) {
retv = fprintf(fp, "%s%s\n", DIRECTORY_BEGIN, retv = fprintf(fp, "%s%s\n", DIRECTORY_BEGIN,
getDirectoryPath(directory)); getDirectoryPath(directory));
if (retv < 0) { if (retv < 0)
ERROR("Failed to write data to database file: %s\n",strerror(errno)); return -1;
return;
}
} }
for (i = 0; i < children->nr; ++i) { 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); const char *base = mpd_basename(cur->path);
retv = fprintf(fp, DIRECTORY_DIR "%s\n", base); retv = fprintf(fp, DIRECTORY_DIR "%s\n", base);
if (retv < 0) { if (retv < 0)
ERROR("Failed to write data to database file: %s\n", return -1;
strerror(errno)); if (writeDirectoryInfo(fp, cur) < 0)
return; return -1;
}
writeDirectoryInfo(fp, cur);
} }
songvec_save(fp, &directory->songs); songvec_save(fp, &directory->songs);
if (directory->path) { if (directory->path &&
retv = fprintf(fp, "%s%s\n", DIRECTORY_END, fprintf(fp, DIRECTORY_END "%s\n",
getDirectoryPath(directory)); getDirectoryPath(directory)) < 0)
if (retv < 0) { return -1;
ERROR("Failed to write data to database file: %s\n",strerror(errno)); return 0;
return;
}
}
} }
static void readDirectoryInfo(FILE * fp, Directory * directory) 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%s\n", DIRECTORY_FS_CHARSET, getFsCharset());
fprintf(fp, "%s\n", DIRECTORY_INFO_END); 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); while (fclose(fp) && errno == EINTR);