libcryfs/implementations/ondisk/OnDiskBlockStore.cpp

41 lines
921 B
C++
Raw Normal View History

#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) {}
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;
}
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
}
}