{}
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;
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());
this->buckets().insert({ defaultPolicyBucketId, PolicyBucket(defaultPolicyBucketId) });
}
- postLoadCleanup(isUpdateValid);
+ postLoadCleanup(filesArePartiallySynced);
}
void InMemoryStorageBackend::saveBackup(void) {
}
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;
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
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);
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;
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: