From 21e19ef69f1ab6efb5d6647b4428c31cef5cde69 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 26 Feb 2014 20:10:31 +0100 Subject: db/simple/Directory: eliminate method LookupSong() Move to SimpleDatabase::GetSong() to give that method more control. --- src/db/plugins/simple/SimpleDatabasePlugin.cxx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/db/plugins/simple/SimpleDatabasePlugin.cxx') diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.cxx b/src/db/plugins/simple/SimpleDatabasePlugin.cxx index 8ba6eef92..e83ef575b 100644 --- a/src/db/plugins/simple/SimpleDatabasePlugin.cxx +++ b/src/db/plugins/simple/SimpleDatabasePlugin.cxx @@ -207,7 +207,25 @@ SimpleDatabase::GetSong(const char *uri, Error &error) const assert(borrowed_song_count == 0); db_lock(); - const Song *song = root->LookupSong(uri); + + auto r = root->LookupDirectory(uri); + if (r.uri == nullptr) { + /* it's a directory */ + db_unlock(); + error.Format(db_domain, DB_NOT_FOUND, + "No such song: %s", uri); + return nullptr; + } + + if (strchr(r.uri, '/') != nullptr) { + /* refers to a URI "below" the actual song */ + db_unlock(); + error.Format(db_domain, DB_NOT_FOUND, + "No such song: %s", uri); + return nullptr; + } + + const Song *song = r.directory->FindSong(r.uri); db_unlock(); if (song == nullptr) { error.Format(db_domain, DB_NOT_FOUND, -- cgit v1.2.3