Migrate from unique_ptr to unique_ref

This commit is contained in:
Sebastian Messmer 2015-07-21 18:22:03 +02:00
parent 43d8174fd4
commit 492caeb418
5 changed files with 12 additions and 14 deletions

View File

@ -12,8 +12,6 @@
#include "messmer/blobstore/implementations/onblocks/BlobOnBlocks.h"
#include "messmer/blockstore/implementations/encrypted/EncryptedBlockStore.h"
using std::unique_ptr;
using std::make_unique;
using std::string;
//TODO Get rid of this in favor of exception hierarchy
@ -38,8 +36,8 @@ namespace cryfs {
constexpr uint32_t CryDevice::BLOCKSIZE_BYTES;
CryDevice::CryDevice(unique_ref<CryConfig> config, unique_ptr<BlockStore> blockStore)
: _blobStore(make_unique_ref<BlobStoreOnBlocks>(make_unique_ref<CachingBlockStore>(make_unique<EncryptedBlockStore<Cipher>>(std::move(blockStore), GetEncryptionKey(config.get()))), BLOCKSIZE_BYTES)), _rootKey(GetOrCreateRootKey(config.get())) {
CryDevice::CryDevice(unique_ref<CryConfig> config, unique_ref<BlockStore> blockStore)
: _blobStore(make_unique_ref<BlobStoreOnBlocks>(make_unique_ref<CachingBlockStore>(make_unique_ref<EncryptedBlockStore<Cipher>>(std::move(blockStore), GetEncryptionKey(config.get()))), BLOCKSIZE_BYTES)), _rootKey(GetOrCreateRootKey(config.get())) {
}
Key CryDevice::GetOrCreateRootKey(CryConfig *config) {

View File

@ -20,7 +20,7 @@ public:
using Cipher = CryConfigLoader::Cipher;
CryDevice(cpputils::unique_ref<CryConfig> config, std::unique_ptr<blockstore::BlockStore> blockStore);
CryDevice(cpputils::unique_ref<CryConfig> config, cpputils::unique_ref<blockstore::BlockStore> blockStore);
virtual ~CryDevice();
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;

View File

@ -19,7 +19,7 @@ using std::make_unique;
int main (int argc, char *argv[])
{
auto blockStore = make_unique<OnDiskBlockStore>(bf::path("/home/heinzi/cryfstest/root"));
auto blockStore = make_unique_ref<OnDiskBlockStore>(bf::path("/home/heinzi/cryfstest/root"));
auto config = cryfs::CryConfigLoader::loadOrCreate(bf::path("/home/heinzi/cryfstest/config.json"));
cryfs::CryDevice device(std::move(config), std::move(blockStore));
fspp::FilesystemImpl fsimpl(&device);

View File

@ -14,7 +14,7 @@ using ::testing::Test;
using cpputils::TempDir;
using cpputils::TempFile;
using cpputils::dynamic_pointer_move;
using std::make_unique;
using cpputils::make_unique_ref;
using blockstore::ondisk::OnDiskBlockStore;
namespace bf = boost::filesystem;
@ -29,27 +29,27 @@ public:
TEST_F(CryFsTest, CreatedRootdirIsLoadableAfterClosing) {
{
CryDevice dev(CryConfigLoader::createNewWithWeakKey(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
CryDevice dev(CryConfigLoader::createNewWithWeakKey(config.path()), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
}
CryDevice dev(CryConfigLoader::loadExisting(config.path()).value(), make_unique<OnDiskBlockStore>(rootdir.path()));
CryDevice dev(CryConfigLoader::loadExisting(config.path()).value(), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
auto root = dev.Load(bf::path("/"));
dynamic_pointer_move<CryDir>(root.get()).get()->children();
}
TEST_F(CryFsTest, UsingStrongKey1_CreatedRootdirIsLoadableAfterClosing) {
{
CryDevice dev(CryConfigLoader::createNew(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
CryDevice dev(CryConfigLoader::createNew(config.path()), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
}
CryDevice dev(CryConfigLoader::loadExisting(config.path()).value(), make_unique<OnDiskBlockStore>(rootdir.path()));
CryDevice dev(CryConfigLoader::loadExisting(config.path()).value(), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
auto root = dev.Load(bf::path("/"));
dynamic_pointer_move<CryDir>(root.get()).get()->children();
}
TEST_F(CryFsTest, UsingStrongKey2_CreatedRootdirIsLoadableAfterClosing) {
{
CryDevice dev(CryConfigLoader::loadOrCreate(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
CryDevice dev(CryConfigLoader::loadOrCreate(config.path()), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
}
CryDevice dev(CryConfigLoader::loadOrCreate(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
CryDevice dev(CryConfigLoader::loadOrCreate(config.path()), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
auto root = dev.Load(bf::path("/"));
dynamic_pointer_move<CryDir>(root.get()).get()->children();
}

View File

@ -20,7 +20,7 @@ public:
: configFile(false) {}
unique_ref<Device> createDevice() override {
auto blockStore = std::make_unique<FakeBlockStore>();
auto blockStore = cpputils::make_unique_ref<FakeBlockStore>();
auto config = CryConfigLoader::loadOrCreateWithWeakKey(configFile.path());
return make_unique_ref<CryDevice>(std::move(config), std::move(blockStore));
}