test/LoadDatabase: ignore tag/charset mismatches
This program shouldn't fail just because the configuration doesn't match - it has no configuration, it's just a dumb test program.
This commit is contained in:
parent
38d8359384
commit
1f495efb46
|
@ -52,7 +52,8 @@ db_save_internal(BufferedOutputStream &os, const Directory &music_root)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
db_load_internal(LineReader &file, Directory &music_root)
|
db_load_internal(LineReader &file, Directory &music_root,
|
||||||
|
bool ignore_config_mismatches)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
unsigned format = 0;
|
unsigned format = 0;
|
||||||
|
@ -81,6 +82,9 @@ db_load_internal(LineReader &file, Directory &music_root)
|
||||||
|
|
||||||
found_charset = true;
|
found_charset = true;
|
||||||
|
|
||||||
|
if (ignore_config_mismatches)
|
||||||
|
continue;
|
||||||
|
|
||||||
const char *new_charset = p;
|
const char *new_charset = p;
|
||||||
const char *const old_charset = GetFSCharset();
|
const char *const old_charset = GetFSCharset();
|
||||||
if (*old_charset != 0
|
if (*old_charset != 0
|
||||||
|
@ -90,6 +94,9 @@ db_load_internal(LineReader &file, Directory &music_root)
|
||||||
"discarding database file",
|
"discarding database file",
|
||||||
new_charset, old_charset);
|
new_charset, old_charset);
|
||||||
} else if ((p = StringAfterPrefix(line, DB_TAG_PREFIX))) {
|
} else if ((p = StringAfterPrefix(line, DB_TAG_PREFIX))) {
|
||||||
|
if (ignore_config_mismatches)
|
||||||
|
continue;
|
||||||
|
|
||||||
const char *name = p;
|
const char *name = p;
|
||||||
TagType tag = tag_name_parse(name);
|
TagType tag = tag_name_parse(name);
|
||||||
if (tag == TAG_NUM_OF_ITEM_TYPES)
|
if (tag == TAG_NUM_OF_ITEM_TYPES)
|
||||||
|
@ -107,6 +114,7 @@ db_load_internal(LineReader &file, Directory &music_root)
|
||||||
throw std::runtime_error("Database format mismatch, "
|
throw std::runtime_error("Database format mismatch, "
|
||||||
"discarding database file");
|
"discarding database file");
|
||||||
|
|
||||||
|
if (!ignore_config_mismatches)
|
||||||
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
|
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
|
||||||
if (IsTagEnabled(i) && !tags[i])
|
if (IsTagEnabled(i) && !tags[i])
|
||||||
throw std::runtime_error("Tag list mismatch, "
|
throw std::runtime_error("Tag list mismatch, "
|
||||||
|
|
|
@ -13,8 +13,12 @@ db_save_internal(BufferedOutputStream &os, const Directory &root);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws #std::runtime_error on error.
|
* Throws #std::runtime_error on error.
|
||||||
|
*
|
||||||
|
* @param ignore_config_mismatches if true, then configuration
|
||||||
|
* mismatches (e.g. enabled tags or filesystem charset) are ignored
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
db_load_internal(LineReader &file, Directory &root);
|
db_load_internal(LineReader &file, Directory &root,
|
||||||
|
bool ignore_config_mismatches=false);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,7 +21,7 @@ try {
|
||||||
|
|
||||||
Directory root{{}, nullptr};
|
Directory root{{}, nullptr};
|
||||||
TextFile line_reader{db_path};
|
TextFile line_reader{db_path};
|
||||||
db_load_internal(line_reader, root);
|
db_load_internal(line_reader, root, true);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
|
Loading…
Reference in New Issue