diff --git a/src/checks.h b/src/checks.h index 2728178..9673de3 100644 --- a/src/checks.h +++ b/src/checks.h @@ -15,6 +15,8 @@ #include #include +#include "sqlite.h" + /* Fix - This is an abstract datatype representing an executable action to fix * an incosistency in the filesystem or metadata database. */ @@ -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 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(path / "s3gw.db")) {} virtual ~Check(){}; enum LogLevel { SILENT, NORMAL, VERBOSE }; bool check(LogLevel log_level = NORMAL); diff --git a/src/checks/metadata_integrity.cc b/src/checks/metadata_integrity.cc index 028686c..957e98b 100644 --- a/src/checks/metadata_integrity.cc +++ b/src/checks/metadata_integrity.cc @@ -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(root_path / "s3gw.db"); -} - -MetadataIntegrityCheck::~MetadataIntegrityCheck() {} - bool MetadataIntegrityCheck::do_check() { std::vector errors; auto callback = [](void* arg, int num_columns, char** column_data, char**) { diff --git a/src/checks/metadata_integrity.h b/src/checks/metadata_integrity.h index d7d021a..0dba6f7 100644 --- a/src/checks/metadata_integrity.h +++ b/src/checks/metadata_integrity.h @@ -14,7 +14,6 @@ #include #include "checks.h" -#include "sqlite.h" class MetadataIntegrityFix : public Fix { private: @@ -30,15 +29,13 @@ class MetadataIntegrityFix : public Fix { }; class MetadataIntegrityCheck : public Check { - private: - std::unique_ptr 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__ diff --git a/src/checks/metadata_schema_version.cc b/src/checks/metadata_schema_version.cc index 5bd719f..814cb95 100644 --- a/src/checks/metadata_schema_version.cc +++ b/src/checks/metadata_schema_version.cc @@ -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(root_path / "s3gw.db"); -} - -MetadataSchemaVersionCheck::~MetadataSchemaVersionCheck() {} - bool MetadataSchemaVersionCheck::do_check() { std::string query = "PRAGMA user_version;"; int version = 0; diff --git a/src/checks/metadata_schema_version.h b/src/checks/metadata_schema_version.h index 87ae84b..7121d57 100644 --- a/src/checks/metadata_schema_version.h +++ b/src/checks/metadata_schema_version.h @@ -19,7 +19,6 @@ #include #include "checks.h" -#include "sqlite.h" class MetadataSchemaVersionFix : public Fix { private: @@ -34,15 +33,13 @@ class MetadataSchemaVersionFix : public Fix { }; class MetadataSchemaVersionCheck : public Check { - private: - std::unique_ptr 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; diff --git a/src/checks/object_integrity.cc b/src/checks/object_integrity.cc index 12f6edb..a2257cd 100644 --- a/src/checks/object_integrity.cc +++ b/src/checks/object_integrity.cc @@ -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(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 diff --git a/src/checks/object_integrity.h b/src/checks/object_integrity.h index 3a2dfa6..6802636 100644 --- a/src/checks/object_integrity.h +++ b/src/checks/object_integrity.h @@ -19,7 +19,6 @@ #define FSCK_SFS_SRC_CHECKS_OBJECT_INTEGRITY_H__ #include "checks.h" -#include "sqlite.h" class ObjectIntegrityFix : public Fix { private: @@ -35,15 +34,13 @@ class ObjectIntegrityFix : public Fix { }; class ObjectIntegrityCheck : public Check { - private: - std::unique_ptr 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__ diff --git a/src/checks/orphaned_metadata.cc b/src/checks/orphaned_metadata.cc index 87dde6e..0eb0e58 100644 --- a/src/checks/orphaned_metadata.cc +++ b/src/checks/orphaned_metadata.cc @@ -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(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 diff --git a/src/checks/orphaned_metadata.h b/src/checks/orphaned_metadata.h index c2da583..889360d 100644 --- a/src/checks/orphaned_metadata.h +++ b/src/checks/orphaned_metadata.h @@ -22,7 +22,6 @@ #include #include "checks.h" -#include "sqlite.h" class OrphanedMetadataFix : public Fix { private: @@ -39,15 +38,13 @@ class OrphanedMetadataFix : public Fix { }; class OrphanedMetadataCheck : public Check { - private: - std::unique_ptr 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__ diff --git a/src/checks/orphaned_objects.cc b/src/checks/orphaned_objects.cc index 8d703a4..bf48f01 100644 --- a/src/checks/orphaned_objects.cc +++ b/src/checks/orphaned_objects.cc @@ -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(root_path / "s3gw.db"); -} - -OrphanedObjectsCheck::~OrphanedObjectsCheck() {} - bool OrphanedObjectsCheck::do_check() { int orphan_count = 0; std::stack stack; diff --git a/src/checks/orphaned_objects.h b/src/checks/orphaned_objects.h index a602a64..2288796 100644 --- a/src/checks/orphaned_objects.h +++ b/src/checks/orphaned_objects.h @@ -24,7 +24,6 @@ #include #include "checks.h" -#include "sqlite.h" class OrphanedObjectsFix : public Fix { private: @@ -55,15 +54,13 @@ class UnexpectedFileFix : public Fix { }; class OrphanedObjectsCheck : public Check { - private: - std::unique_ptr 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__