aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-11-04 18:48:22 +0100
committerMax Kellermann <max@duempel.org>2009-11-04 18:48:22 +0100
commite96dc9a14ceae8f9ccc3a25c9cd92301be2aeff3 (patch)
tree2a6a2cdd53f013a9686dd6a05caae014c43dbbb7 /src
parenta434c35eb46ff71e2b0441595dcc7985e1b292c2 (diff)
downloadmpd-e96dc9a14ceae8f9ccc3a25c9cd92301be2aeff3.tar.gz
mpd-e96dc9a14ceae8f9ccc3a25c9cd92301be2aeff3.tar.xz
mpd-e96dc9a14ceae8f9ccc3a25c9cd92301be2aeff3.zip
database: rescan after metadata_to_use change
Store a list of supported tag items in the database. When loading a database which does not have a matching list, we must rescan in order to get the missing information.
Diffstat (limited to 'src')
-rw-r--r--src/database.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/database.c b/src/database.c
index 4ecc58f2d..70fce0c18 100644
--- a/src/database.c
+++ b/src/database.c
@@ -24,6 +24,8 @@
#include "path.h"
#include "stats.h"
#include "text_file.h"
+#include "tag.h"
+#include "tag_internal.h"
#include "config.h"
#include <glib.h>
@@ -44,6 +46,7 @@
#define DB_FORMAT_PREFIX "format: "
#define DIRECTORY_MPD_VERSION "mpd_version: "
#define DIRECTORY_FS_CHARSET "fs_charset: "
+#define DB_TAG_PREFIX "tag: "
enum {
DB_FORMAT = 1,
@@ -241,6 +244,11 @@ db_save(void)
fprintf(fp, DB_FORMAT_PREFIX "%u\n", DB_FORMAT);
fprintf(fp, "%s%s\n", DIRECTORY_MPD_VERSION, VERSION);
fprintf(fp, "%s%s\n", DIRECTORY_FS_CHARSET, path_get_fs_charset());
+
+ for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
+ if (!ignore_tag_items[i])
+ fprintf(fp, DB_TAG_PREFIX "%s\n", tag_item_names[i]);
+
fprintf(fp, "%s\n", DIRECTORY_INFO_END);
if (directory_save(fp, music_root) < 0) {
@@ -268,6 +276,7 @@ db_load(GError **error)
int format = 0;
bool found_charset = false, found_version = false;
bool success;
+ bool tags[TAG_NUM_OF_ITEM_TYPES];
assert(database_path != NULL);
assert(music_root != NULL);
@@ -290,6 +299,8 @@ db_load(GError **error)
return false;
}
+ memset(tags, false, sizeof(tags));
+
while ((line = read_text_line(fp, buffer)) != NULL &&
strcmp(line, DIRECTORY_INFO_END) != 0) {
if (g_str_has_prefix(line, DB_FORMAT_PREFIX)) {
@@ -330,6 +341,18 @@ db_load(GError **error)
g_string_free(buffer, true);
return false;
}
+ } else if (g_str_has_prefix(line, DB_TAG_PREFIX)) {
+ const char *name = line + sizeof(DB_TAG_PREFIX) - 1;
+ enum tag_type tag = tag_name_parse(name);
+ if (tag == TAG_NUM_OF_ITEM_TYPES) {
+ g_set_error(error, db_quark(), 0,
+ "Unrecognized tag '%s', "
+ "discarding database file",
+ name);
+ return false;
+ }
+
+ tags[tag] = true;
} else {
fclose(fp);
g_set_error(error, db_quark(), 0,
@@ -346,6 +369,15 @@ db_load(GError **error)
return false;
}
+ for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) {
+ if (!ignore_tag_items[i] && !tags[i]) {
+ g_set_error(error, db_quark(), 0,
+ "Tag list mismatch, "
+ "discarding database file");
+ return false;
+ }
+ }
+
g_debug("reading DB");
success = directory_load(fp, music_root, buffer, error);