Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
65 lines (64 sloc) 1.85 KB
#pragma once
#include <kcpolydb.h>
#include <iostream>
#include <string>
#include "yadfs_exception.h"
#include "std_metadata.h"
#include "sha256.h"
class DataStore {
DataStore(const std::string& path) {
std::cerr << path << "\n";
if (! {
std::string error_message("Can't open datastore ");
error_message += path + ": ";
error_message += mDB.error().name();
throw yadfs_exception(error_message);
~DataStore() {
bool getContentForObject(const std::string& path, std::string& content) {
return get(keyForContent(path), content);
bool getMetadataForObject(const std::string& path, const std::string& key, std::string& value) {
return get(keyForMetadata(path, key), value);
bool setContentForObject(const std::string& path, const std::string& content) {
bool success=true;
if (!content.empty()) {
std::string sha256(compute_sha256((const uint8_t*) &content[0], content.size()));
success=setMetadataForObject(path, YADFS_META_SHA256, sha256);
return success && set(keyForContent(path), content);
bool setMetadataForObject(const std::string& path, const std::string& key, std::string& value) {
return set(keyForMetadata(path, key), value);
std::string keyForContent(const std::string& path) {
std::string prefix("content:");
return prefix+path;
std::string keyForMetadata(const std::string& path, const std::string& metadata) {
std::string prefix("meta:");
return prefix + metadata + ":"+path;
bool get(const std::string& key, std::string& value) {
if (!mDB.get(key, &value)) {
return false;
return true;
bool set(const std::string& key, const std::string& value) {
return mDB.set(key, value);
kyotocabinet::PolyDB mDB;
DataStore(const DataStore&);
DataStore& operator=(const DataStore&);
Something went wrong with that request. Please try again.