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

Commit

Permalink
Move metadata up into Check class
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Serong <[email protected]>
  • Loading branch information
tserong committed Nov 14, 2023
1 parent 40097c5 commit 6136130
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 69 deletions.
8 changes: 7 additions & 1 deletion src/checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <string>
#include <vector>

#include "sqlite.h"

/* Fix - This is an abstract datatype representing an executable action to fix
* an incosistency in the filesystem or metadata database.
*/
Expand All @@ -40,12 +42,16 @@ class Check {
const std::string check_name;
enum Fatality { FATAL, NONFATAL } fatality;
const std::filesystem::path& root_path;
std::unique_ptr<Database> metadata;
virtual bool do_check() = 0;
void log_verbose(const std::string& msg) const;

public:
Check(const std::string& name, Fatality f, const std::filesystem::path& path)
: check_name(name), fatality(f), root_path(path) {}
: check_name(name),
fatality(f),
root_path(path),
metadata(std::make_unique<Database>(path / "s3gw.db")) {}
virtual ~Check(){};
enum LogLevel { SILENT, NORMAL, VERBOSE };
bool check(LogLevel log_level = NORMAL);
Expand Down
8 changes: 0 additions & 8 deletions src/checks/metadata_integrity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ std::string MetadataIntegrityFix::to_string() const {
return msg;
}

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

MetadataIntegrityCheck::~MetadataIntegrityCheck() {}

bool MetadataIntegrityCheck::do_check() {
std::vector<std::string> errors;
auto callback = [](void* arg, int num_columns, char** column_data, char**) {
Expand Down
9 changes: 3 additions & 6 deletions src/checks/metadata_integrity.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <memory>

#include "checks.h"
#include "sqlite.h"

class MetadataIntegrityFix : public Fix {
private:
Expand All @@ -30,15 +29,13 @@ class MetadataIntegrityFix : public Fix {
};

class MetadataIntegrityCheck : public Check {
private:
std::unique_ptr<Database> metadata;

protected:
virtual bool do_check() override;

public:
MetadataIntegrityCheck(const std::filesystem::path& path);
virtual ~MetadataIntegrityCheck() override;
MetadataIntegrityCheck(const std::filesystem::path& path)
: Check("metadata integrity", FATAL, path) {}
virtual ~MetadataIntegrityCheck() override{};
};

#endif // FSCK_SFS_SRC_CHECKS_METADATA_INTEGRITY_H__
9 changes: 0 additions & 9 deletions src/checks/metadata_schema_version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ std::string MetadataSchemaVersionFix::to_string() const {
"; expected: " + std::to_string(EXPECTED_METADATA_SCHEMA_VERSION);
}

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

MetadataSchemaVersionCheck::~MetadataSchemaVersionCheck() {}

bool MetadataSchemaVersionCheck::do_check() {
std::string query = "PRAGMA user_version;";
int version = 0;
Expand Down
9 changes: 3 additions & 6 deletions src/checks/metadata_schema_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <memory>

#include "checks.h"
#include "sqlite.h"

class MetadataSchemaVersionFix : public Fix {
private:
Expand All @@ -34,15 +33,13 @@ class MetadataSchemaVersionFix : public Fix {
};

class MetadataSchemaVersionCheck : public Check {
private:
std::unique_ptr<Database> metadata;

protected:
virtual bool do_check() override;

public:
MetadataSchemaVersionCheck(const std::filesystem::path& path);
virtual ~MetadataSchemaVersionCheck() override;
MetadataSchemaVersionCheck(const std::filesystem::path& path)
: Check("metadata schema version", FATAL, path) {}
virtual ~MetadataSchemaVersionCheck() override {}
};

const int EXPECTED_METADATA_SCHEMA_VERSION = 4;
Expand Down
7 changes: 0 additions & 7 deletions src/checks/object_integrity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ std::string ObjectIntegrityFix::to_string() const {
reason;
}

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

ObjectIntegrityCheck::~ObjectIntegrityCheck() {}

bool ObjectIntegrityCheck::do_check() {
int fail_count = 0;
// TODO: is there any sense in implementing this as a separate check
Expand Down
9 changes: 3 additions & 6 deletions src/checks/object_integrity.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#define FSCK_SFS_SRC_CHECKS_OBJECT_INTEGRITY_H__

#include "checks.h"
#include "sqlite.h"

class ObjectIntegrityFix : public Fix {
private:
Expand All @@ -35,15 +34,13 @@ class ObjectIntegrityFix : public Fix {
};

class ObjectIntegrityCheck : public Check {
private:
std::unique_ptr<Database> metadata;

protected:
virtual bool do_check() override;

public:
ObjectIntegrityCheck(const std::filesystem::path& path);
virtual ~ObjectIntegrityCheck() override;
ObjectIntegrityCheck(const std::filesystem::path& path)
: Check("object integrity", NONFATAL, path) {}
virtual ~ObjectIntegrityCheck() override{};
};

#endif // FSCK_SFS_SRC_CHECKS_OBJECT_INTEGRITY_H__
7 changes: 0 additions & 7 deletions src/checks/orphaned_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ std::string OrphanedMetadataFix::to_string() const {
return "orphaned metadata: " + obj_path.string();
}

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

OrphanedMetadataCheck::~OrphanedMetadataCheck() {}

bool OrphanedMetadataCheck::do_check() {
int orphan_count = 0;
// TODO: Should we do a join here with the objects table in order
Expand Down
9 changes: 3 additions & 6 deletions src/checks/orphaned_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <memory>

#include "checks.h"
#include "sqlite.h"

class OrphanedMetadataFix : public Fix {
private:
Expand All @@ -39,15 +38,13 @@ class OrphanedMetadataFix : public Fix {
};

class OrphanedMetadataCheck : public Check {
private:
std::unique_ptr<Database> metadata;

protected:
virtual bool do_check() override;

public:
OrphanedMetadataCheck(const std::filesystem::path& path);
virtual ~OrphanedMetadataCheck() override;
OrphanedMetadataCheck(const std::filesystem::path& path)
: Check("orphaned metadata", NONFATAL, path) {}
virtual ~OrphanedMetadataCheck() override {}
};

#endif // FSCK_SFS_SRC_CHECKS_ORPHANED_METADATA_H__
7 changes: 0 additions & 7 deletions src/checks/orphaned_objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ std::string UnexpectedFileFix::to_string() const {
return "Found unexpected mystery file: " + obj_path.string();
}

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

OrphanedObjectsCheck::~OrphanedObjectsCheck() {}

bool OrphanedObjectsCheck::do_check() {
int orphan_count = 0;
std::stack<std::filesystem::path> stack;
Expand Down
9 changes: 3 additions & 6 deletions src/checks/orphaned_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <memory>

#include "checks.h"
#include "sqlite.h"

class OrphanedObjectsFix : public Fix {
private:
Expand Down Expand Up @@ -55,15 +54,13 @@ class UnexpectedFileFix : public Fix {
};

class OrphanedObjectsCheck : public Check {
private:
std::unique_ptr<Database> metadata;

protected:
virtual bool do_check() override;

public:
OrphanedObjectsCheck(const std::filesystem::path& path);
virtual ~OrphanedObjectsCheck() override;
OrphanedObjectsCheck(const std::filesystem::path& path)
: Check("orphaned objects", NONFATAL, path) {}
virtual ~OrphanedObjectsCheck() override {}
};

#endif // FSCK_SFS_SRC_CHECKS_ORPHANED_OBJECTS_H__

0 comments on commit 6136130

Please sign in to comment.