diff --git a/NEWS b/NEWS index b0447c9b0..054059bfb 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ ver 0.21.25 (not yet released) * protocol: - fix crash when using "rangeid" while playing +* database + - simple: automatically scan new mounts * storage - fix disappearing mounts after mounting twice - udisks: fix reading ".mpdignore" diff --git a/src/command/StorageCommands.cxx b/src/command/StorageCommands.cxx index 2dea85e8d..4d5a58c96 100644 --- a/src/command/StorageCommands.cxx +++ b/src/command/StorageCommands.cxx @@ -220,8 +220,10 @@ handle_mount(Client &client, Request args, Response &r) #ifdef ENABLE_DATABASE if (auto *db = dynamic_cast(instance.GetDatabase())) { + bool need_update; + try { - db->Mount(local_uri, remote_uri); + need_update = !db->Mount(local_uri, remote_uri); } catch (...) { composite.Unmount(local_uri); throw; @@ -230,6 +232,12 @@ handle_mount(Client &client, Request args, Response &r) // TODO: call Instance::OnDatabaseModified()? // TODO: trigger database update? instance.EmitIdle(IDLE_DATABASE); + + if (need_update) { + UpdateService *update = client.GetInstance().update; + if (update != nullptr) + update->Enqueue(local_uri, false); + } } #endif diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.cxx b/src/db/plugins/simple/SimpleDatabasePlugin.cxx index 5350db6d8..4cae15c02 100644 --- a/src/db/plugins/simple/SimpleDatabasePlugin.cxx +++ b/src/db/plugins/simple/SimpleDatabasePlugin.cxx @@ -428,7 +428,7 @@ IsUnsafeChar(char ch) return !IsSafeChar(ch); } -void +bool SimpleDatabase::Mount(const char *local_uri, const char *storage_uri) { if (cache_path.IsNull()) @@ -447,9 +447,11 @@ SimpleDatabase::Mount(const char *local_uri, const char *storage_uri) compress); db->Open(); - // TODO: update the new database instance? + bool exists = db->FileExists(); Mount(local_uri, std::move(db)); + + return exists; } inline DatabasePtr diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.hxx b/src/db/plugins/simple/SimpleDatabasePlugin.hxx index bdc90f6c1..5e525a999 100644 --- a/src/db/plugins/simple/SimpleDatabasePlugin.hxx +++ b/src/db/plugins/simple/SimpleDatabasePlugin.hxx @@ -103,9 +103,11 @@ public: /** * Throws #std::runtime_error on error. + * + * @return false if the mounted database needs to be updated */ gcc_nonnull_all - void Mount(const char *local_uri, const char *storage_uri); + bool Mount(const char *local_uri, const char *storage_uri); gcc_nonnull_all bool Unmount(const char *uri) noexcept;