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,10 +114,11 @@ 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");
|
||||||
|
|
||||||
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
|
if (!ignore_config_mismatches)
|
||||||
if (IsTagEnabled(i) && !tags[i])
|
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
|
||||||
throw std::runtime_error("Tag list mismatch, "
|
if (IsTagEnabled(i) && !tags[i])
|
||||||
"discarding database file");
|
throw std::runtime_error("Tag list mismatch, "
|
||||||
|
"discarding database file");
|
||||||
|
|
||||||
const ScopeDatabaseLock protect;
|
const ScopeDatabaseLock protect;
|
||||||
directory_load(file, music_root);
|
directory_load(file, music_root);
|
||||||
|
|
|
@ -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