summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Main.cxx4
-rw-r--r--src/command/StorageCommands.cxx4
-rw-r--r--src/storage/Configured.cxx9
-rw-r--r--src/storage/Configured.hxx4
-rw-r--r--src/storage/Registry.cxx5
-rw-r--r--src/storage/Registry.hxx6
-rw-r--r--src/storage/StoragePlugin.hxx5
-rw-r--r--src/storage/StorageState.cxx6
-rw-r--r--src/storage/plugins/CurlStorage.cxx4
-rw-r--r--src/storage/plugins/LocalStorage.cxx4
-rw-r--r--src/storage/plugins/LocalStorage.hxx6
-rw-r--r--src/storage/plugins/NfsStorage.cxx5
-rw-r--r--src/storage/plugins/SmbclientStorage.cxx4
-rw-r--r--test/run_storage.cxx8
-rw-r--r--test/test_translate_song.cxx4
15 files changed, 46 insertions, 32 deletions
diff --git a/src/Main.cxx b/src/Main.cxx
index 6d9f8d88e..2a556af62 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -175,13 +175,13 @@ glue_mapper_init()
static void
InitStorage(EventLoop &event_loop)
{
- Storage *storage = CreateConfiguredStorage(event_loop);
+ auto storage = CreateConfiguredStorage(event_loop);
if (storage == nullptr)
return;
CompositeStorage *composite = new CompositeStorage();
instance->storage = composite;
- composite->Mount("", storage);
+ composite->Mount("", storage.release());
}
/**
diff --git a/src/command/StorageCommands.cxx b/src/command/StorageCommands.cxx
index e32e51b4c..bb06f821e 100644
--- a/src/command/StorageCommands.cxx
+++ b/src/command/StorageCommands.cxx
@@ -199,13 +199,13 @@ handle_mount(Client &client, Request args, Response &r)
}
auto &event_loop = instance.io_thread.GetEventLoop();
- Storage *storage = CreateStorageURI(event_loop, remote_uri);
+ auto storage = CreateStorageURI(event_loop, remote_uri);
if (storage == nullptr) {
r.Error(ACK_ERROR_ARG, "Unrecognized storage URI");
return CommandResult::ERROR;
}
- composite.Mount(local_uri, storage);
+ composite.Mount(local_uri, storage.release());
instance.EmitIdle(IDLE_MOUNT);
#ifdef ENABLE_DATABASE
diff --git a/src/storage/Configured.cxx b/src/storage/Configured.cxx
index 4b2cc1b5c..d0ee3d543 100644
--- a/src/storage/Configured.cxx
+++ b/src/storage/Configured.cxx
@@ -20,6 +20,7 @@
#include "config.h"
#include "Configured.hxx"
#include "Registry.hxx"
+#include "StorageInterface.hxx"
#include "plugins/LocalStorage.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/ConfigError.hxx"
@@ -30,10 +31,10 @@
#include <assert.h>
-static Storage *
+static std::unique_ptr<Storage>
CreateConfiguredStorageUri(EventLoop &event_loop, const char *uri)
{
- Storage *storage = CreateStorageURI(event_loop, uri);
+ auto storage = CreateStorageURI(event_loop, uri);
if (storage == nullptr)
throw FormatRuntimeError("Unrecognized storage URI: %s", uri);
@@ -50,7 +51,7 @@ GetConfiguredMusicDirectory()
return path;
}
-static Storage *
+static std::unique_ptr<Storage>
CreateConfiguredStorageLocal()
{
AllocatedPath path = GetConfiguredMusicDirectory();
@@ -62,7 +63,7 @@ CreateConfiguredStorageLocal()
return CreateLocalStorage(path);
}
-Storage *
+std::unique_ptr<Storage>
CreateConfiguredStorage(EventLoop &event_loop)
{
auto uri = config_get_string(ConfigOption::MUSIC_DIR);
diff --git a/src/storage/Configured.hxx b/src/storage/Configured.hxx
index 4b630af04..084f720a4 100644
--- a/src/storage/Configured.hxx
+++ b/src/storage/Configured.hxx
@@ -23,6 +23,8 @@
#include "check.h"
#include "Compiler.h"
+#include <memory>
+
class Storage;
class EventLoop;
@@ -32,7 +34,7 @@ class EventLoop;
*
* Throws #std::runtime_error on error.
*/
-Storage *
+std::unique_ptr<Storage>
CreateConfiguredStorage(EventLoop &event_loop);
/**
diff --git a/src/storage/Registry.cxx b/src/storage/Registry.cxx
index a919bd9da..85374886e 100644
--- a/src/storage/Registry.cxx
+++ b/src/storage/Registry.cxx
@@ -20,6 +20,7 @@
#include "config.h"
#include "Registry.hxx"
#include "StoragePlugin.hxx"
+#include "StorageInterface.hxx"
#include "plugins/LocalStorage.hxx"
#include "plugins/SmbclientStorage.hxx"
#include "plugins/NfsStorage.hxx"
@@ -54,7 +55,7 @@ GetStoragePluginByName(const char *name) noexcept
return nullptr;
}
-Storage *
+std::unique_ptr<Storage>
CreateStorageURI(EventLoop &event_loop, const char *uri)
{
for (auto i = storage_plugins; *i != nullptr; ++i) {
@@ -63,7 +64,7 @@ CreateStorageURI(EventLoop &event_loop, const char *uri)
if (plugin.create_uri == nullptr)
continue;
- Storage *storage = plugin.create_uri(event_loop, uri);
+ auto storage = plugin.create_uri(event_loop, uri);
if (storage != nullptr)
return storage;
}
diff --git a/src/storage/Registry.hxx b/src/storage/Registry.hxx
index 998756da7..4a4136067 100644
--- a/src/storage/Registry.hxx
+++ b/src/storage/Registry.hxx
@@ -23,6 +23,8 @@
#include "check.h"
#include "Compiler.h"
+#include <memory>
+
struct StoragePlugin;
class Storage;
class EventLoop;
@@ -37,8 +39,8 @@ gcc_nonnull_all gcc_pure
const StoragePlugin *
GetStoragePluginByName(const char *name) noexcept;
-gcc_nonnull_all gcc_malloc
-Storage *
+gcc_nonnull_all
+std::unique_ptr<Storage>
CreateStorageURI(EventLoop &event_loop, const char *uri);
#endif
diff --git a/src/storage/StoragePlugin.hxx b/src/storage/StoragePlugin.hxx
index 94ea58ea3..93aacd357 100644
--- a/src/storage/StoragePlugin.hxx
+++ b/src/storage/StoragePlugin.hxx
@@ -22,6 +22,8 @@
#include "check.h"
+#include <memory>
+
class Storage;
class EventLoop;
@@ -31,7 +33,8 @@ struct StoragePlugin {
/**
* Throws #std::runtime_error on error.
*/
- Storage *(*create_uri)(EventLoop &event_loop, const char *uri);
+ std::unique_ptr<Storage> (*create_uri)(EventLoop &event_loop,
+ const char *uri);
};
#endif
diff --git a/src/storage/StorageState.cxx b/src/storage/StorageState.cxx
index 9ca35caa6..de60954a6 100644
--- a/src/storage/StorageState.cxx
+++ b/src/storage/StorageState.cxx
@@ -101,7 +101,7 @@ storage_state_restore(const char *line, TextFile &file, Instance &instance)
FormatDebug(storage_domain, "Restoring mount %s => %s", uri.c_str(), url.c_str());
auto &event_loop = instance.io_thread.GetEventLoop();
- Storage *storage = CreateStorageURI(event_loop, url.c_str());
+ auto storage = CreateStorageURI(event_loop, url.c_str());
if (storage == nullptr) {
FormatError(storage_domain, "Unrecognized storage URI: %s", url.c_str());
return true;
@@ -112,7 +112,6 @@ storage_state_restore(const char *line, TextFile &file, Instance &instance)
try {
((SimpleDatabase *)db)->Mount(uri.c_str(), url.c_str());
} catch (...) {
- delete storage;
FormatError(std::current_exception(),
"Failed to restore mount to %s",
url.c_str());
@@ -120,7 +119,8 @@ storage_state_restore(const char *line, TextFile &file, Instance &instance)
}
}
- ((CompositeStorage*)instance.storage)->Mount(uri.c_str(), storage);
+ ((CompositeStorage*)instance.storage)->Mount(uri.c_str(),
+ storage.release());
return true;
}
diff --git a/src/storage/plugins/CurlStorage.cxx b/src/storage/plugins/CurlStorage.cxx
index caba4579f..e2696c1ac 100644
--- a/src/storage/plugins/CurlStorage.cxx
+++ b/src/storage/plugins/CurlStorage.cxx
@@ -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 = {
diff --git a/src/storage/plugins/LocalStorage.cxx b/src/storage/plugins/LocalStorage.cxx
index b03981ada..35ac1826c 100644
--- a/src/storage/plugins/LocalStorage.cxx
+++ b/src/storage/plugins/LocalStorage.cxx
@@ -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 = {
diff --git a/src/storage/plugins/LocalStorage.hxx b/src/storage/plugins/LocalStorage.hxx
index 1dba7a2c0..ae1a89ee2 100644
--- a/src/storage/plugins/LocalStorage.hxx
+++ b/src/storage/plugins/LocalStorage.hxx
@@ -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
diff --git a/src/storage/plugins/NfsStorage.cxx b/src/storage/plugins/NfsStorage.cxx
index e28ef1189..cf9659150 100644
--- a/src/storage/plugins/NfsStorage.cxx
+++ b/src/storage/plugins/NfsStorage.cxx
@@ -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 = {
diff --git a/src/storage/plugins/SmbclientStorage.cxx b/src/storage/plugins/SmbclientStorage.cxx
index 5468892d2..e7b8d8f13 100644
--- a/src/storage/plugins/SmbclientStorage.cxx
+++ b/src/storage/plugins/SmbclientStorage.cxx
@@ -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 = {
diff --git a/test/run_storage.cxx b/test/run_storage.cxx
index 32ba8ed47..267b98750 100644
--- a/test/run_storage.cxx
+++ b/test/run_storage.cxx
@@ -34,10 +34,10 @@
#include <string.h>
#include <time.h>
-static Storage *
+static std::unique_ptr<Storage>
MakeStorage(EventLoop &event_loop, const char *uri)
{
- Storage *storage = CreateStorageURI(event_loop, uri);
+ auto storage = CreateStorageURI(event_loop, uri);
if (storage == nullptr)
throw std::runtime_error("Unrecognized storage URI");
@@ -108,8 +108,8 @@ try {
const char *const path = argv[3];
- std::unique_ptr<Storage> storage(MakeStorage(io_thread.GetEventLoop(),
- storage_uri));
+ auto storage = MakeStorage(io_thread.GetEventLoop(),
+ storage_uri);
return Ls(*storage, path);
} else {
diff --git a/test/test_translate_song.cxx b/test/test_translate_song.cxx
index a2144b50a..0526f761f 100644
--- a/test/test_translate_song.cxx
+++ b/test/test_translate_song.cxx
@@ -14,6 +14,7 @@
#include "ls.hxx"
#include "Log.hxx"
#include "db/DatabaseSong.hxx"
+#include "storage/StorageInterface.hxx"
#include "storage/plugins/LocalStorage.hxx"
#include "Mapper.hxx"
#include "util/ChronoUtil.hxx"
@@ -309,7 +310,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(TranslateSongTest);
int
main(gcc_unused int argc, gcc_unused char **argv)
{
- storage = CreateLocalStorage(Path::FromFS(music_directory));
+ auto _storage = CreateLocalStorage(Path::FromFS(music_directory));
+ storage = _storage.get();
CppUnit::TextUi::TestRunner runner;
auto &registry = CppUnit::TestFactoryRegistry::getRegistry();