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 "caching/commands.h"
#include "caching/metadata.h"
@@ -212,12 +213,18 @@ namespace {
error_state metadata_check(string const &path, flags const &fs,
bool &needs_check_set) {
block_manager<>::ptr bm = open_bm(path, block_manager<>::READ_ONLY);
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);
mapping_reporter mapping_rep(out);
hint_reporter hint_rep(out);
@@ -229,8 +236,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. cache_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);

View File

@@ -365,7 +365,7 @@ caching::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()));
}