Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Add Check::Fatality
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Serong <[email protected]>
  • Loading branch information
tserong committed Nov 3, 2023
1 parent 32520bd commit a991a64
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
15 changes: 11 additions & 4 deletions src/checks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,24 @@ bool run_checks(const std::filesystem::path& path, bool should_fix) {
bool all_checks_passed = true;

std::vector<std::shared_ptr<Check>> checks;
// TODO: consider which of these checks should abort the entire process.
// I'm thinking in particular here of the metadata schema version check
// because if that fails, subsequent checks might not be valid.
checks.emplace_back(std::make_shared<MetadataSchemaVersionCheck>(path));
checks.emplace_back(std::make_shared<OrphanedObjectsCheck>(path));
checks.emplace_back(std::make_shared<OrphanedMetadataCheck>(path));
checks.emplace_back(std::make_shared<ObjectIntegrityCheck>(path));

for (std::shared_ptr<Check> check : checks) {
all_checks_passed = check->check() ? all_checks_passed : false;
bool this_check_passed = check->check();
check->show();
if (!this_check_passed) {
all_checks_passed = false;
if (check->is_fatal()) {
// Don't do any more checks if this check failure is fatal.
// TODO: integrate check->fix() here (try the fix, re-run the
// check, reset the failure state) otherwise you're basically
// screwed if there's a fatal failure.
break;
}
}
if (should_fix) {
check->fix();
}
Expand Down
5 changes: 4 additions & 1 deletion src/checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ class Fix {
class Check {
protected:
std::vector<std::shared_ptr<Fix>> fixes;
enum Fatality { FATAL, NONFATAL } fatality;
const std::filesystem::path& root_path;

public:
Check(const std::filesystem::path& path) : root_path(path) {}
Check(Fatality f, const std::filesystem::path& path)
: fatality(f), root_path(path) {}
virtual ~Check(){};
virtual bool check() = 0;
bool is_fatal() { return fatality == FATAL; }
void fix();
void show();
};
Expand Down
2 changes: 1 addition & 1 deletion src/checks/metadata_schema_version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ std::string MetadataSchemaVersionFix::to_string() const {
MetadataSchemaVersionCheck::MetadataSchemaVersionCheck(
const std::filesystem::path& path
)
: Check(path) {
: Check(FATAL, path) {
metadata = std::make_unique<Database>(root_path / "s3gw.db");
}

Expand Down
2 changes: 1 addition & 1 deletion src/checks/object_integrity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ std::string ObjectIntegrityFix::to_string() const {
}

ObjectIntegrityCheck::ObjectIntegrityCheck(const std::filesystem::path& path)
: Check(path) {
: Check(NONFATAL, path) {
metadata = std::make_unique<Database>(root_path / "s3gw.db");
}

Expand Down
2 changes: 1 addition & 1 deletion src/checks/orphaned_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ std::string OrphanedMetadataFix::to_string() const {
}

OrphanedMetadataCheck::OrphanedMetadataCheck(const std::filesystem::path& path)
: Check(path) {
: Check(NONFATAL, path) {
metadata = std::make_unique<Database>(root_path / "s3gw.db");
}

Expand Down
2 changes: 1 addition & 1 deletion src/checks/orphaned_objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ std::string UnexpectedFileFix::to_string() const {
}

OrphanedObjectsCheck::OrphanedObjectsCheck(const std::filesystem::path& path)
: Check(path) {
: Check(NONFATAL, path) {
metadata = std::make_unique<Database>(root_path / "s3gw.db");
}

Expand Down

0 comments on commit a991a64

Please sign in to comment.