libcryfs/implementations/ondisk/OnDiskBlockStore.cpp

43 lines
1.0 KiB
C++
Raw Normal View History

2015-02-17 00:23:33 +01:00
#include <messmer/blockstore/implementations/ondisk/OnDiskBlock.h>
#include <messmer/blockstore/implementations/ondisk/OnDiskBlockStore.h>
2014-12-09 17:19:59 +01:00
using std::unique_ptr;
using std::make_unique;
using std::string;
using std::mutex;
using std::lock_guard;
namespace bf = boost::filesystem;
namespace blockstore {
namespace ondisk {
OnDiskBlockStore::OnDiskBlockStore(const boost::filesystem::path &rootdir)
: _rootdir(rootdir) {}
unique_ptr<Block> OnDiskBlockStore::create(const Key &key, size_t size) {
2015-01-24 22:08:41 +01:00
auto block = OnDiskBlock::CreateOnDisk(_rootdir, key, size);
2014-12-09 17:19:59 +01:00
if (!block) {
return nullptr;
}
return std::move(block);
2014-12-09 17:19:59 +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
}
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
}
}