aboutsummaryrefslogtreecommitdiffstats
path: root/src/database.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/database.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/database.c b/src/database.c
index 4d36169c7..8e927bfc4 100644
--- a/src/database.c
+++ b/src/database.c
@@ -41,9 +41,14 @@
#define DIRECTORY_INFO_BEGIN "info_begin"
#define DIRECTORY_INFO_END "info_end"
+#define DB_FORMAT_PREFIX "format: "
#define DIRECTORY_MPD_VERSION "mpd_version: "
#define DIRECTORY_FS_CHARSET "fs_charset: "
+enum {
+ DB_FORMAT = 0,
+};
+
static char *database_path;
static struct directory *music_root;
@@ -233,6 +238,7 @@ db_save(void)
/* block signals when writing the db so we don't get a corrupted db */
fprintf(fp, "%s\n", DIRECTORY_INFO_BEGIN);
+ 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());
fprintf(fp, "%s\n", DIRECTORY_INFO_END);
@@ -259,6 +265,7 @@ db_load(GError **error)
struct stat st;
GString *buffer = g_string_sized_new(1024);
char *line;
+ int format = 0;
bool found_charset = false, found_version = false;
bool success;
@@ -285,7 +292,9 @@ db_load(GError **error)
while ((line = read_text_line(fp, buffer)) != NULL &&
strcmp(line, DIRECTORY_INFO_END) != 0) {
- if (g_str_has_prefix(line, DIRECTORY_MPD_VERSION)) {
+ if (g_str_has_prefix(line, DB_FORMAT_PREFIX)) {
+ format = atoi(line + sizeof(DB_FORMAT_PREFIX) - 1);
+ } else if (g_str_has_prefix(line, DIRECTORY_MPD_VERSION)) {
if (found_version) {
fclose(fp);
g_set_error(error, db_quark(), 0,
@@ -330,6 +339,13 @@ db_load(GError **error)
}
}
+ if (format != DB_FORMAT) {
+ g_set_error(error, db_quark(), 0,
+ "Database format mismatch, "
+ "discarding database file");
+ return false;
+ }
+
g_debug("reading DB");
success = directory_load(fp, music_root, buffer, error);