database: simplify db_load()

Removed a superfluous closure.
This commit is contained in:
Max Kellermann 2008-10-09 15:21:18 +02:00
parent 5583b6c5e1
commit 5dc4c325aa

View File

@ -238,6 +238,10 @@ db_load(void)
FILE *fp = NULL; FILE *fp = NULL;
char *dbFile = db_get_file(); char *dbFile = db_get_file();
struct stat st; struct stat st;
char buffer[100];
int bufferSize = 100;
int foundFsCharset = 0;
int foundVersion = 0;
if (!music_root) if (!music_root)
music_root = directory_new("", NULL); music_root = directory_new("", NULL);
@ -249,24 +253,23 @@ db_load(void)
} }
/* get initial info */ /* get initial info */
{
char buffer[100];
int bufferSize = 100;
int foundFsCharset = 0;
int foundVersion = 0;
if (!myFgets(buffer, bufferSize, fp)) if (!myFgets(buffer, bufferSize, fp))
FATAL("Error reading db, fgets\n"); FATAL("Error reading db, fgets\n");
if (0 == strcmp(DIRECTORY_INFO_BEGIN, buffer)) {
if (0 != strcmp(DIRECTORY_INFO_BEGIN, buffer)) {
ERROR("db info not found in db file\n");
ERROR("you should recreate the db using --create-db\n");
while (fclose(fp) && errno == EINTR) ;
return -1;
}
while (myFgets(buffer, bufferSize, fp) && while (myFgets(buffer, bufferSize, fp) &&
0 != strcmp(DIRECTORY_INFO_END, buffer)) { 0 != strcmp(DIRECTORY_INFO_END, buffer)) {
if (!prefixcmp(buffer, DIRECTORY_MPD_VERSION)) if (!prefixcmp(buffer, DIRECTORY_MPD_VERSION)) {
{
if (foundVersion) if (foundVersion)
FATAL("already found version in db\n"); FATAL("already found version in db\n");
foundVersion = 1; foundVersion = 1;
} else if (!prefixcmp(buffer, } else if (!prefixcmp(buffer, DIRECTORY_FS_CHARSET)) {
DIRECTORY_FS_CHARSET)) {
char *fsCharset; char *fsCharset;
char *tempCharset; char *tempCharset;
@ -286,18 +289,10 @@ db_load(void)
"recreate the db?\n"); "recreate the db?\n");
setFsCharset(fsCharset); setFsCharset(fsCharset);
} }
} else { } else
FATAL("directory: unknown line in db info: %s\n", FATAL("directory: unknown line in db info: %s\n",
buffer); buffer);
} }
}
} else {
ERROR("db info not found in db file\n");
ERROR("you should recreate the db using --create-db\n");
while (fclose(fp) && errno == EINTR) ;
return -1;
}
}
DEBUG("reading DB\n"); DEBUG("reading DB\n");