Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
2fd51826
Commit
2fd51826
authored
Mar 19, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/Interface: GetSong() throws exception on error
parent
7ad7caa2
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
43 additions
and
67 deletions
+43
-67
PlaylistPrint.cxx
src/PlaylistPrint.cxx
+1
-3
SongLoader.cxx
src/SongLoader.cxx
+8
-12
SongLoader.hxx
src/SongLoader.hxx
+3
-4
QueueCommands.cxx
src/command/QueueCommands.cxx
+6
-8
StickerCommands.cxx
src/command/StickerCommands.cxx
+7
-12
DatabaseSong.cxx
src/db/DatabaseSong.cxx
+3
-5
DatabaseSong.hxx
src/db/DatabaseSong.hxx
+2
-3
Interface.hxx
src/db/Interface.hxx
+1
-2
ProxyDatabasePlugin.cxx
src/db/plugins/ProxyDatabasePlugin.cxx
+2
-3
SimpleDatabasePlugin.cxx
src/db/plugins/simple/SimpleDatabasePlugin.cxx
+2
-2
SimpleDatabasePlugin.hxx
src/db/plugins/simple/SimpleDatabasePlugin.hxx
+1
-2
UpnpDatabasePlugin.cxx
src/db/plugins/upnp/UpnpDatabasePlugin.cxx
+2
-3
PlaylistUpdate.cxx
src/queue/PlaylistUpdate.cxx
+1
-1
SongSticker.cxx
src/sticker/SongSticker.cxx
+3
-5
test_translate_song.cxx
test/test_translate_song.cxx
+1
-2
No files found.
src/PlaylistPrint.cxx
View file @
2fd51826
...
...
@@ -127,9 +127,7 @@ PrintSongDetails(Response &r, Partition &partition, const char *uri_utf8)
const
LightSong
*
song
;
try
{
song
=
db
->
GetSong
(
uri_utf8
,
IgnoreError
());
if
(
song
==
nullptr
)
return
false
;
song
=
db
->
GetSong
(
uri_utf8
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
return
false
;
}
...
...
src/SongLoader.cxx
View file @
2fd51826
...
...
@@ -38,21 +38,20 @@ SongLoader::SongLoader(const Client &_client)
#endif
DetachedSong
*
SongLoader
::
LoadFromDatabase
(
const
char
*
uri
,
Error
&
error
)
const
SongLoader
::
LoadFromDatabase
(
const
char
*
uri
)
const
{
#ifdef ENABLE_DATABASE
if
(
db
!=
nullptr
)
return
DatabaseDetachSong
(
*
db
,
*
storage
,
uri
,
error
);
return
DatabaseDetachSong
(
*
db
,
*
storage
,
uri
);
#else
(
void
)
uri
;
(
void
)
error
;
#endif
throw
PlaylistError
(
PlaylistResult
::
NO_SUCH_SONG
,
"No database"
);
}
DetachedSong
*
SongLoader
::
LoadFile
(
const
char
*
path_utf8
,
Path
path_fs
,
Error
&
error
)
const
SongLoader
::
LoadFile
(
const
char
*
path_utf8
,
Path
path_fs
)
const
{
#ifdef ENABLE_DATABASE
if
(
storage
!=
nullptr
)
{
...
...
@@ -60,10 +59,8 @@ SongLoader::LoadFile(const char *path_utf8, Path path_fs, Error &error) const
if
(
suffix
!=
nullptr
)
/* this path was relative to the music
directory - obtain it from the database */
return
LoadFromDatabase
(
suffix
,
error
);
return
LoadFromDatabase
(
suffix
);
}
#else
(
void
)
error
;
#endif
DetachedSong
song
(
path_utf8
);
...
...
@@ -74,7 +71,7 @@ SongLoader::LoadFile(const char *path_utf8, Path path_fs, Error &error) const
}
DetachedSong
*
SongLoader
::
LoadSong
(
const
LocatedUri
&
located_uri
,
Error
&
error
)
const
SongLoader
::
LoadSong
(
const
LocatedUri
&
located_uri
)
const
{
switch
(
located_uri
.
type
)
{
case
LocatedUri
:
:
Type
::
UNKNOWN
:
...
...
@@ -84,11 +81,10 @@ SongLoader::LoadSong(const LocatedUri &located_uri, Error &error) const
return
new
DetachedSong
(
located_uri
.
canonical_uri
);
case
LocatedUri
:
:
Type
::
RELATIVE
:
return
LoadFromDatabase
(
located_uri
.
canonical_uri
,
error
);
return
LoadFromDatabase
(
located_uri
.
canonical_uri
);
case
LocatedUri
:
:
Type
::
PATH
:
return
LoadFile
(
located_uri
.
canonical_uri
,
located_uri
.
path
,
error
);
return
LoadFile
(
located_uri
.
canonical_uri
,
located_uri
.
path
);
}
gcc_unreachable
();
...
...
@@ -110,5 +106,5 @@ SongLoader::LoadSong(const char *uri_utf8, Error &error) const
if
(
located_uri
.
IsUnknown
())
return
nullptr
;
return
LoadSong
(
located_uri
,
error
);
return
LoadSong
(
located_uri
);
}
src/SongLoader.hxx
View file @
2fd51826
...
...
@@ -68,18 +68,17 @@ public:
}
#endif
DetachedSong
*
LoadSong
(
const
LocatedUri
&
uri
,
Error
&
error
)
const
;
DetachedSong
*
LoadSong
(
const
LocatedUri
&
uri
)
const
;
gcc_nonnull_all
DetachedSong
*
LoadSong
(
const
char
*
uri_utf8
,
Error
&
error
)
const
;
private
:
gcc_nonnull_all
DetachedSong
*
LoadFromDatabase
(
const
char
*
uri
,
Error
&
error
)
const
;
DetachedSong
*
LoadFromDatabase
(
const
char
*
uri
)
const
;
gcc_nonnull_all
DetachedSong
*
LoadFile
(
const
char
*
path_utf8
,
Path
path_fs
,
Error
&
error
)
const
;
DetachedSong
*
LoadFile
(
const
char
*
path_utf8
,
Path
path_fs
)
const
;
};
#endif
src/command/QueueCommands.cxx
View file @
2fd51826
...
...
@@ -41,17 +41,14 @@
#include <memory>
#include <limits>
static
CommandResult
AddUri
(
Client
&
client
,
const
LocatedUri
&
uri
,
Response
&
r
)
static
void
AddUri
(
Client
&
client
,
const
LocatedUri
&
uri
)
{
Error
error
;
std
::
unique_ptr
<
DetachedSong
>
song
(
SongLoader
(
client
).
LoadSong
(
uri
,
error
));
if
(
song
==
nullptr
)
return
print_error
(
r
,
error
);
std
::
unique_ptr
<
DetachedSong
>
song
(
SongLoader
(
client
).
LoadSong
(
uri
));
assert
(
song
);
auto
&
partition
=
client
.
partition
;
partition
.
playlist
.
AppendSong
(
partition
.
pc
,
std
::
move
(
*
song
));
return
CommandResult
::
OK
;
}
static
CommandResult
...
...
@@ -98,7 +95,8 @@ handle_add(Client &client, Request args, Response &r)
case
LocatedUri
:
:
Type
::
ABSOLUTE
:
case
LocatedUri
:
:
Type
::
PATH
:
return
AddUri
(
client
,
located_uri
,
r
);
AddUri
(
client
,
located_uri
);
return
CommandResult
::
OK
;
case
LocatedUri
:
:
Type
::
RELATIVE
:
return
AddDatabaseSelection
(
client
,
located_uri
.
canonical_uri
,
...
...
src/command/StickerCommands.cxx
View file @
2fd51826
...
...
@@ -62,9 +62,7 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
/* get song song_id key */
if
(
args
.
size
==
4
&&
StringIsEqual
(
cmd
,
"get"
))
{
const
LightSong
*
song
=
db
->
GetSong
(
args
[
2
],
error
);
if
(
song
==
nullptr
)
return
print_error
(
r
,
error
);
const
LightSong
*
song
=
db
->
GetSong
(
args
[
2
]);
const
auto
value
=
sticker_song_get_value
(
*
song
,
args
[
3
],
error
);
...
...
@@ -82,9 +80,8 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
return
CommandResult
::
OK
;
/* list song song_id */
}
else
if
(
args
.
size
==
3
&&
StringIsEqual
(
cmd
,
"list"
))
{
const
LightSong
*
song
=
db
->
GetSong
(
args
[
2
],
error
);
if
(
song
==
nullptr
)
return
print_error
(
r
,
error
);
const
LightSong
*
song
=
db
->
GetSong
(
args
[
2
]);
assert
(
song
!=
nullptr
);
Sticker
*
sticker
=
sticker_song_get
(
*
song
,
error
);
db
->
ReturnSong
(
song
);
...
...
@@ -97,9 +94,8 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
return
CommandResult
::
OK
;
/* set song song_id id key */
}
else
if
(
args
.
size
==
5
&&
StringIsEqual
(
cmd
,
"set"
))
{
const
LightSong
*
song
=
db
->
GetSong
(
args
[
2
],
error
);
if
(
song
==
nullptr
)
return
print_error
(
r
,
error
);
const
LightSong
*
song
=
db
->
GetSong
(
args
[
2
]);
assert
(
song
!=
nullptr
);
bool
ret
=
sticker_song_set_value
(
*
song
,
args
[
3
],
args
[
4
],
error
);
...
...
@@ -117,9 +113,8 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
/* delete song song_id [key] */
}
else
if
((
args
.
size
==
3
||
args
.
size
==
4
)
&&
StringIsEqual
(
cmd
,
"delete"
))
{
const
LightSong
*
song
=
db
->
GetSong
(
args
[
2
],
error
);
if
(
song
==
nullptr
)
return
print_error
(
r
,
error
);
const
LightSong
*
song
=
db
->
GetSong
(
args
[
2
]);
assert
(
song
!=
nullptr
);
bool
ret
=
args
.
size
==
3
?
sticker_song_delete
(
*
song
,
error
)
...
...
src/db/DatabaseSong.cxx
View file @
2fd51826
...
...
@@ -41,12 +41,10 @@ DatabaseDetachSong(const Storage &storage, const LightSong &song)
}
DetachedSong
*
DatabaseDetachSong
(
const
Database
&
db
,
const
Storage
&
storage
,
const
char
*
uri
,
Error
&
error
)
DatabaseDetachSong
(
const
Database
&
db
,
const
Storage
&
storage
,
const
char
*
uri
)
{
const
LightSong
*
tmp
=
db
.
GetSong
(
uri
,
error
);
if
(
tmp
==
nullptr
)
return
nullptr
;
const
LightSong
*
tmp
=
db
.
GetSong
(
uri
);
assert
(
tmp
!=
nullptr
);
DetachedSong
*
song
=
new
DetachedSong
(
DatabaseDetachSong
(
storage
,
*
tmp
));
...
...
src/db/DatabaseSong.hxx
View file @
2fd51826
...
...
@@ -26,7 +26,6 @@ struct LightSong;
class
Database
;
class
Storage
;
class
DetachedSong
;
class
Error
;
/**
* "Detach" the #Song object, i.e. convert it to a #DetachedSong
...
...
@@ -44,7 +43,7 @@ DatabaseDetachSong(const Storage &storage, const LightSong &song);
*/
gcc_malloc
gcc_nonnull_all
DetachedSong
*
DatabaseDetachSong
(
const
Database
&
db
,
const
Storage
&
storage
,
const
char
*
uri
,
Error
&
error
);
DatabaseDetachSong
(
const
Database
&
db
,
const
Storage
&
storage
,
const
char
*
uri
);
#endif
src/db/Interface.hxx
View file @
2fd51826
...
...
@@ -73,8 +73,7 @@ public:
* @param uri_utf8 the URI of the song within the music
* directory (UTF-8)
*/
virtual
const
LightSong
*
GetSong
(
const
char
*
uri_utf8
,
Error
&
error
)
const
=
0
;
virtual
const
LightSong
*
GetSong
(
const
char
*
uri_utf8
)
const
=
0
;
/**
* Mark the song object as "unused". Call this on objects
...
...
src/db/plugins/ProxyDatabasePlugin.cxx
View file @
2fd51826
...
...
@@ -115,8 +115,7 @@ public:
virtual
void
Open
()
override
;
virtual
void
Close
()
override
;
virtual
const
LightSong
*
GetSong
(
const
char
*
uri_utf8
,
Error
&
error
)
const
override
;
const
LightSong
*
GetSong
(
const
char
*
uri_utf8
)
const
override
;
void
ReturnSong
(
const
LightSong
*
song
)
const
override
;
virtual
bool
Visit
(
const
DatabaseSelection
&
selection
,
...
...
@@ -519,7 +518,7 @@ ProxyDatabase::OnIdle()
}
const
LightSong
*
ProxyDatabase
::
GetSong
(
const
char
*
uri
,
gcc_unused
Error
&
error
)
const
ProxyDatabase
::
GetSong
(
const
char
*
uri
)
const
{
// TODO: eliminate the const_cast
const_cast
<
ProxyDatabase
*>
(
this
)
->
EnsureConnected
();
...
...
src/db/plugins/simple/SimpleDatabasePlugin.cxx
View file @
2fd51826
...
...
@@ -229,7 +229,7 @@ SimpleDatabase::Close()
}
const
LightSong
*
SimpleDatabase
::
GetSong
(
const
char
*
uri
,
Error
&
error
)
const
SimpleDatabase
::
GetSong
(
const
char
*
uri
)
const
{
assert
(
root
!=
nullptr
);
assert
(
prefixed_light_song
==
nullptr
);
...
...
@@ -244,7 +244,7 @@ SimpleDatabase::GetSong(const char *uri, Error &error) const
protect
.
unlock
();
const
LightSong
*
song
=
r
.
directory
->
mounted_database
->
GetSong
(
r
.
uri
,
error
);
r
.
directory
->
mounted_database
->
GetSong
(
r
.
uri
);
if
(
song
==
nullptr
)
return
nullptr
;
...
...
src/db/plugins/simple/SimpleDatabasePlugin.hxx
View file @
2fd51826
...
...
@@ -110,8 +110,7 @@ public:
virtual
void
Open
()
override
;
virtual
void
Close
()
override
;
const
LightSong
*
GetSong
(
const
char
*
uri_utf8
,
Error
&
error
)
const
override
;
const
LightSong
*
GetSong
(
const
char
*
uri_utf8
)
const
override
;
void
ReturnSong
(
const
LightSong
*
song
)
const
override
;
virtual
bool
Visit
(
const
DatabaseSelection
&
selection
,
...
...
src/db/plugins/upnp/UpnpDatabasePlugin.cxx
View file @
2fd51826
...
...
@@ -82,8 +82,7 @@ public:
virtual
void
Open
()
override
;
virtual
void
Close
()
override
;
virtual
const
LightSong
*
GetSong
(
const
char
*
uri_utf8
,
Error
&
error
)
const
override
;
virtual
const
LightSong
*
GetSong
(
const
char
*
uri_utf8
)
const
override
;
void
ReturnSong
(
const
LightSong
*
song
)
const
override
;
virtual
bool
Visit
(
const
DatabaseSelection
&
selection
,
...
...
@@ -202,7 +201,7 @@ UpnpDatabase::ReturnSong(const LightSong *_song) const
// Get song info by path. We can receive either the id path, or the titles
// one
const
LightSong
*
UpnpDatabase
::
GetSong
(
const
char
*
uri
,
gcc_unused
Error
&
error
)
const
UpnpDatabase
::
GetSong
(
const
char
*
uri
)
const
{
auto
vpath
=
stringToTokens
(
uri
,
"/"
,
true
);
if
(
vpath
.
size
()
<
2
)
...
...
src/queue/PlaylistUpdate.cxx
View file @
2fd51826
...
...
@@ -35,7 +35,7 @@ UpdatePlaylistSong(const Database &db, DetachedSong &song)
const
LightSong
*
original
;
try
{
original
=
db
.
GetSong
(
song
.
GetURI
()
,
IgnoreError
()
);
original
=
db
.
GetSong
(
song
.
GetURI
());
}
catch
(
const
std
::
runtime_error
&
e
)
{
return
false
;
}
...
...
src/sticker/SongSticker.cxx
View file @
2fd51826
...
...
@@ -93,11 +93,9 @@ sticker_song_find_cb(const char *uri, const char *value, void *user_data)
const
Database
*
db
=
data
->
db
;
try
{
const
LightSong
*
song
=
db
->
GetSong
(
uri
,
IgnoreError
());
if
(
song
!=
nullptr
)
{
data
->
func
(
*
song
,
value
,
data
->
user_data
);
db
->
ReturnSong
(
song
);
}
const
LightSong
*
song
=
db
->
GetSong
(
uri
);
data
->
func
(
*
song
,
value
,
data
->
user_data
);
db
->
ReturnSong
(
song
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
}
}
...
...
test/test_translate_song.cxx
View file @
2fd51826
...
...
@@ -111,8 +111,7 @@ static const char *uri2 = "foo/bar.ogg";
DetachedSong
*
DatabaseDetachSong
(
gcc_unused
const
Database
&
db
,
gcc_unused
const
Storage
&
_storage
,
const
char
*
uri
,
gcc_unused
Error
&
error
)
const
char
*
uri
)
{
if
(
strcmp
(
uri
,
uri2
)
==
0
)
return
new
DetachedSong
(
uri
,
MakeTag2a
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment