Detect XML in *_check tools (#86)

* [*_check] Detect XML in cache_check and era_check

This is based on previous commit b10d8d4440.

* [*_check] Fix typo in check_superblock
This commit is contained in:
csonto
2017-10-05 14:47:10 +02:00
committed by Joe Thornber
parent db9259d303
commit 5b5aa971a0
9 changed files with 66 additions and 21 deletions

View File

@@ -14,6 +14,7 @@
#include "base/error_state.h"
#include "base/error_string.h"
#include "base/file_utils.h"
#include "base/nested_output.h"
#include "era/commands.h"
#include "era/writeset_tree.h"
@@ -185,11 +186,19 @@ namespace {
return info;
}
error_state metadata_check(block_manager<>::ptr bm, flags const &fs) {
error_state metadata_check(string const &path, flags const &fs) {
nested_output out(cerr, 2);
if (fs.quiet_)
out.disable();
if (file_utils::get_file_length(path) < persistent_data::MD_BLOCK_SIZE) {
out << "Metadata device/file too small. Is this binary metadata?"
<< end_message();
return FATAL;
}
block_manager<>::ptr bm = open_bm(path, block_manager<>::READ_ONLY);
superblock_reporter sb_rep(out);
out << "examining superblock" << end_message();
@@ -198,8 +207,11 @@ namespace {
check_superblock(bm, bm->get_nr_blocks(), sb_rep);
}
if (sb_rep.get_error() == FATAL)
if (sb_rep.get_error() == FATAL) {
if (check_for_xml(bm))
out << "This looks like XML. era_check only checks the binary metadata format." << end_message();
return FATAL;
}
superblock sb = read_superblock(bm);
transaction_manager::ptr tm = open_tm(bm, SUPERBLOCK_LOCATION);
@@ -233,8 +245,7 @@ namespace {
throw runtime_error(msg.str());
}
block_manager<>::ptr bm = open_bm(path, block_manager<>::READ_ONLY);
err = metadata_check(bm, fs);
err = metadata_check(path, fs);
return err == NO_ERROR ? 0 : 1;
}

View File

@@ -283,7 +283,7 @@ era::check_superblock(superblock const &sb,
if (sb.magic != SUPERBLOCK_MAGIC) {
ostringstream msg;
msg << "magic in incorrect: " << sb.magic;
msg << "magic is incorrect: " << sb.magic;
visitor.visit(superblock_invalid(msg.str()));
}