libcryfs/implementations/ondisk/OnDiskBlockStore.cpp
Sebastian Meßmer 417a701636 - BlockStore::create() gets the data of the new block as a parameter
- Fixed numBlocks() in OnDiskBlockStore, FakeBlockStore, CachingBlockStore, ...
- CachingBlockStore caches created blocks and doesn't directly create them in the underlying blockstore
2015-04-18 14:47:12 +02:00

41 lines
921 B
C++

#include "OnDiskBlock.h"
#include "OnDiskBlockStore.h"
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) {}
unique_ptr<Block> OnDiskBlockStore::tryCreate(const Key &key, Data data) {
auto block = OnDiskBlock::CreateOnDisk(_rootdir, key, std::move(data));
if (!block) {
return nullptr;
}
return std::move(block);
}
unique_ptr<Block> OnDiskBlockStore::load(const Key &key) {
return OnDiskBlock::LoadFromDisk(_rootdir, key);
}
void OnDiskBlockStore::remove(unique_ptr<Block> block) {
Key key = block->key();
block.reset();
OnDiskBlock::RemoveFromDisk(_rootdir, key);
}
uint64_t OnDiskBlockStore::numBlocks() const {
return std::distance(bf::directory_iterator(_rootdir), bf::directory_iterator());
}
}
}