Cleanup the code 94/315294/2
authorKrzysztof Malysa <k.malysa@samsung.com>
Fri, 19 Jul 2024 16:01:26 +0000 (18:01 +0200)
committerKrzysztof Malysa <k.malysa@samsung.com>
Thu, 1 Aug 2024 09:07:36 +0000 (11:07 +0200)
Change-Id: I7ef926f261f1362aa87551b993f0df83cc2f6715

src/common/response/Response.h
src/storage/ChecksumValidator.cpp
src/storage/ChecksumValidator.h
src/storage/InMemoryStorageBackend.cpp
src/storage/InMemoryStorageBackend.h
src/storage/Integrity.h

index 51e1a19d4b61719999c70eae626a70f9ce7b6b77..f2ff8bbb6ec6f99e27debd6fd6ebffb4c1877fe5 100644 (file)
@@ -33,6 +33,8 @@
 
 namespace Cynara {
 
+class RequestContext;
+
 class Response {
 public:
     Response(ProtocolFrameSequenceNumber sequenceNumber) : m_sequenceNumber(sequenceNumber) {
index 5ebb12cbc2b638eb6ba60693b3ae95d38950917a..8c69628400143837f2906e9feae3e9c6552fe99e 100644 (file)
@@ -72,7 +72,7 @@ const std::string ChecksumValidator::generate(const std::string &data) {
 }
 
 void ChecksumValidator::compare(std::istream &stream, const std::string &pathname,
-                                bool isBackupValid) {
+                                bool readingFromBackup) {
     if (isChecksumIndex(pathname)) {
         return;
     }
@@ -87,7 +87,7 @@ void ChecksumValidator::compare(std::istream &stream, const std::string &pathnam
     std::string filename(::basename(pathnameDuplicate.get()));
     std::stringstream copyStream;
 
-    if (isBackupValid) {
+    if (readingFromBackup) {
         auto backupSuffixPos = filename.rfind(PathConfig::StoragePath::backupFilenameSuffix);
         size_t suffixSize = PathConfig::StoragePath::backupFilenameSuffix.size();
 
index ecb0f674d4de9b8a31d5035776037a9947379768..6fde33a0d9caeddfbda60ddf1db4dd6b0a35ded5 100644 (file)
@@ -43,7 +43,7 @@ public:
     ChecksumValidator(const std::string &path) : m_dbPath(path) {}
 
     void load(std::istream &stream);
-    void compare(std::istream &stream, const std::string &pathname, bool isBackupValid);
+    void compare(std::istream &stream, const std::string &pathname, bool readingFromBackup);
 
     void clear(void) {
         m_sums.clear();
index 12a0bd2762dc2de604ff9d44d523a34c04eccb3d..f7f220a9a2cf3a4e92e40afb8a0317f3b390a1f7 100644 (file)
@@ -64,13 +64,13 @@ InMemoryStorageBackend::InMemoryStorageBackend(const std::string &path)
 {}
 
 void InMemoryStorageBackend::load() {
-    bool isUpdateValid = m_integrity.backupGuardExists();
+    bool filesArePartiallySynced = m_integrity.backupGuardExists();
 
     std::string bucketSuffix = "";
     std::string indexFilename = m_dbPath + PathConfig::StoragePath::indexFilename;
     std::string chsFilename = m_dbPath + PathConfig::StoragePath::checksumFilename;
 
-    if (isUpdateValid) {
+    if (filesArePartiallySynced) {
         bucketSuffix += PathConfig::StoragePath::backupFilenameSuffix;
         indexFilename += PathConfig::StoragePath::backupFilenameSuffix;
         chsFilename += PathConfig::StoragePath::backupFilenameSuffix;
@@ -78,15 +78,15 @@ void InMemoryStorageBackend::load() {
 
     try {
         std::ifstream chsStream;
-        openFileStream(chsStream, chsFilename, isUpdateValid);
+        openFileStream(chsStream, chsFilename, filesArePartiallySynced);
         m_checksum.load(chsStream);
 
         auto indexStream = std::make_shared<std::ifstream>();
-        openFileStream(*indexStream, indexFilename, isUpdateValid);
+        openFileStream(*indexStream, indexFilename, filesArePartiallySynced);
 
         StorageDeserializer storageDeserializer(indexStream,
             std::bind(&InMemoryStorageBackend::bucketStreamOpener, this,
-                      std::placeholders::_1, bucketSuffix, isUpdateValid));
+                      std::placeholders::_1, bucketSuffix, filesArePartiallySynced));
 
         storageDeserializer.initBuckets(buckets());
         storageDeserializer.loadBuckets(buckets());
@@ -103,7 +103,7 @@ void InMemoryStorageBackend::load() {
         this->buckets().insert({ defaultPolicyBucketId, PolicyBucket(defaultPolicyBucketId) });
     }
 
-    postLoadCleanup(isUpdateValid);
+    postLoadCleanup(filesArePartiallySynced);
 }
 
 void InMemoryStorageBackend::saveBackup(void) {
@@ -252,23 +252,23 @@ void InMemoryStorageBackend::dumpDatabase(const std::shared_ptr<std::ofstream> &
 }
 
 void InMemoryStorageBackend::openFileStream(std::ifstream &stream, const std::string &filename,
-                                            bool isUpdateValid) {
+                                            bool filesArePartiallySynced) {
     stream.open(filename);
 
     if (!stream.is_open()) {
         throw FileNotFoundException(filename);
     }
 
-    m_checksum.compare(stream, filename, isUpdateValid);
+    m_checksum.compare(stream, filename, filesArePartiallySynced);
 }
 
 std::shared_ptr<BucketDeserializer> InMemoryStorageBackend::bucketStreamOpener(
-        const PolicyBucketId &bucketId, const std::string &filenameSuffix, bool isUpdateValid) {
+        const PolicyBucketId &bucketId, const std::string &filenameSuffix, bool filesArePartiallySynced) {
     std::string bucketFilename = m_dbPath + PathConfig::StoragePath::bucketFilenamePrefix +
             bucketId + filenameSuffix;
     auto bucketStream = std::make_shared<std::ifstream>();
     try {
-        openFileStream(*bucketStream, bucketFilename, isUpdateValid);
+        openFileStream(*bucketStream, bucketFilename, filesArePartiallySynced);
         return std::make_shared<BucketDeserializer>(bucketStream, bucketFilename);
     } catch (const FileNotFoundException &) {
         return nullptr;
@@ -288,8 +288,8 @@ std::shared_ptr<StorageSerializer<ChecksumStream> > InMemoryStorageBackend::buck
     return std::make_shared<StorageSerializer<ChecksumStream> >(bucketStream);
 }
 
-void InMemoryStorageBackend::postLoadCleanup(bool isUpdateValid) {
-    if (isUpdateValid) {
+void InMemoryStorageBackend::postLoadCleanup(bool filesArePartiallySynced) {
+    if (filesArePartiallySynced) {
         m_integrity.revalidatePrimaryDatabase(buckets());
     }
     //in case there were unnecessary files in db directory
index 34150df552b386c5574793f41a9d497e12b5871d..51858ed7b21081f4e48bb240ff840198d1658fbe 100644 (file)
@@ -59,6 +59,7 @@ public:
     virtual ~InMemoryStorageBackend() {};
 
     virtual void load(void);
+    // Saves database as backup files and hardlinks as normal files, then removes the backup files
     virtual void save(void);
 
     virtual PolicyBucket searchDefaultBucket(const PolicyKey &key);
@@ -69,6 +70,7 @@ public:
     virtual void deleteBucket(const PolicyBucketId &bucketId);
     virtual bool hasBucket(const PolicyBucketId &bucketId);
     virtual void deletePolicy(const PolicyBucketId &bucketId, const PolicyKey &key);
+    // Deletes in all buckets entries pointing to @p bucketId
     virtual void deleteLinking(const PolicyBucketId &bucketId);
     virtual PolicyBucket::Policies listPolicies(const PolicyBucketId &bucketId,
                                                 const PolicyKey &filter) const;
@@ -76,18 +78,20 @@ public:
                                const PolicyKey &filter);
 
 protected:
+    // Saves database as backup files and stores checksums to @p chsStream
     void dumpDatabase(const std::shared_ptr<std::ofstream> &chsStream);
-    void openFileStream(std::ifstream &stream, const std::string &filename, bool isBackupValid);
+    void openFileStream(std::ifstream &stream, const std::string &filename, bool filesArePartiallySynced);
     std::shared_ptr<BucketDeserializer> bucketStreamOpener(const PolicyBucketId &bucketId,
                                                            const std::string &fileNameSuffix,
-                                                           bool isBackupValid);
+                                                           bool filesArePartiallySynced);
 
     template<typename StreamType>
     void openDumpFileStream(StreamType &stream, const std::string &filename);
     std::shared_ptr<StorageSerializer<ChecksumStream> > bucketDumpStreamOpener(
             const PolicyBucketId &bucketId, const std::shared_ptr<std::ofstream> &chsStream);
 
-    virtual void postLoadCleanup(bool isBackupValid);
+    virtual void postLoadCleanup(bool filesArePartiallySynced);
+    // Saves database as backup files
     void saveBackup(void);
 
 private:
index adf677425dd24db413088775257606090fb26965..66d8dae42e4fc632333d61b83380951eb11a9eda 100644 (file)
@@ -46,6 +46,7 @@ public:
     virtual bool backupGuardExists(void) const;
     virtual void createBackupGuard(void) const;
     virtual void syncDatabase(const Buckets &buckets, bool syncBackup);
+    // Hardlinks the backup files as primary files and then removes the backup files
     virtual void revalidatePrimaryDatabase(const Buckets &buckets);
     virtual void deleteNonIndexedFiles(BucketPresenceTester tester);