storage/Plugin: return std::unique_ptr<Storage>

This commit is contained in:
Max Kellermann
2018-01-02 16:11:17 +01:00
parent 3f4f7b0a53
commit 3c5e4e2788
15 changed files with 46 additions and 32 deletions

View File

@@ -549,14 +549,14 @@ CurlStorage::OpenDirectory(const char *uri_utf8)
return HttpListDirectoryOperation(*curl, uri.c_str()).Perform();
}
static Storage *
static std::unique_ptr<Storage>
CreateCurlStorageURI(EventLoop &event_loop, const char *uri)
{
if (strncmp(uri, "http://", 7) != 0 &&
strncmp(uri, "https://", 8) != 0)
return nullptr;
return new CurlStorage(event_loop, uri);
return std::make_unique<CurlStorage>(event_loop, uri);
}
const StoragePlugin curl_storage_plugin = {

View File

@@ -179,10 +179,10 @@ LocalDirectoryReader::GetInfo(bool follow)
return Stat(AllocatedPath::Build(base_fs, reader.GetEntry()), follow);
}
Storage *
std::unique_ptr<Storage>
CreateLocalStorage(Path base_fs)
{
return new LocalStorage(base_fs);
return std::make_unique<LocalStorage>(base_fs);
}
const StoragePlugin local_storage_plugin = {

View File

@@ -23,14 +23,16 @@
#include "check.h"
#include "Compiler.h"
#include <memory>
struct StoragePlugin;
class Storage;
class Path;
extern const StoragePlugin local_storage_plugin;
gcc_malloc gcc_nonnull_all
Storage *
gcc_nonnull_all
std::unique_ptr<Storage>
CreateLocalStorage(Path base_fs);
#endif

View File

@@ -390,7 +390,7 @@ NfsStorage::OpenDirectory(const char *uri_utf8)
return operation.ToReader();
}
static Storage *
static std::unique_ptr<Storage>
CreateNfsStorageURI(EventLoop &event_loop, const char *base)
{
if (strncmp(base, "nfs://", 6) != 0)
@@ -406,7 +406,8 @@ CreateNfsStorageURI(EventLoop &event_loop, const char *base)
nfs_set_base(server.c_str(), mount);
return new NfsStorage(event_loop, base, server.c_str(), mount);
return std::make_unique<NfsStorage>(event_loop, base,
server.c_str(), mount);
}
const StoragePlugin nfs_storage_plugin = {

View File

@@ -179,7 +179,7 @@ SmbclientDirectoryReader::GetInfo(gcc_unused bool follow)
return ::GetInfo(path.c_str());
}
static Storage *
static std::unique_ptr<Storage>
CreateSmbclientStorageURI(gcc_unused EventLoop &event_loop, const char *base)
{
if (strncmp(base, "smb://", 6) != 0)
@@ -198,7 +198,7 @@ CreateSmbclientStorageURI(gcc_unused EventLoop &event_loop, const char *base)
throw MakeErrno("smbc_new_context() failed");
}
return new SmbclientStorage(base, ctx2);
return std::make_unique<SmbclientStorage>(base, ctx2);
}
const StoragePlugin smbclient_storage_plugin = {