2015-03-12 14:27:51 +01:00
|
|
|
#include "OnDiskBlock.h"
|
|
|
|
#include "OnDiskBlockStore.h"
|
2014-12-09 17:19:59 +01:00
|
|
|
|
|
|
|
using std::unique_ptr;
|
|
|
|
using std::make_unique;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
namespace bf = boost::filesystem;
|
|
|
|
|
|
|
|
namespace blockstore {
|
|
|
|
namespace ondisk {
|
|
|
|
|
|
|
|
OnDiskBlockStore::OnDiskBlockStore(const boost::filesystem::path &rootdir)
|
|
|
|
: _rootdir(rootdir) {}
|
|
|
|
|
2015-04-18 14:47:12 +02:00
|
|
|
unique_ptr<Block> OnDiskBlockStore::tryCreate(const Key &key, Data data) {
|
|
|
|
auto block = OnDiskBlock::CreateOnDisk(_rootdir, key, std::move(data));
|
2014-12-09 17:19:59 +01:00
|
|
|
|
|
|
|
if (!block) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-12-09 20:36:32 +01:00
|
|
|
return std::move(block);
|
2014-12-09 17:19:59 +01:00
|
|
|
}
|
|
|
|
|
2014-12-09 20:36:32 +01:00
|
|
|
unique_ptr<Block> OnDiskBlockStore::load(const Key &key) {
|
2015-01-24 22:08:41 +01:00
|
|
|
return OnDiskBlock::LoadFromDisk(_rootdir, key);
|
2014-12-09 17:19:59 +01:00
|
|
|
}
|
|
|
|
|
2015-02-22 16:53:49 +01:00
|
|
|
void OnDiskBlockStore::remove(unique_ptr<Block> block) {
|
|
|
|
Key key = block->key();
|
|
|
|
block.reset();
|
2015-02-22 00:29:21 +01:00
|
|
|
OnDiskBlock::RemoveFromDisk(_rootdir, key);
|
|
|
|
}
|
|
|
|
|
2015-02-23 21:07:07 +01:00
|
|
|
uint64_t OnDiskBlockStore::numBlocks() const {
|
|
|
|
return std::distance(bf::directory_iterator(_rootdir), bf::directory_iterator());
|
|
|
|
}
|
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
}
|
|
|
|
}
|