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
5b8dce74
Commit
5b8dce74
authored
Feb 28, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/simple: throw DatabaseError on error
parent
de938eb6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
41 deletions
+34
-41
StorageCommands.cxx
src/command/StorageCommands.cxx
+7
-2
SimpleDatabasePlugin.cxx
src/db/plugins/simple/SimpleDatabasePlugin.cxx
+26
-38
SimpleDatabasePlugin.hxx
src/db/plugins/simple/SimpleDatabasePlugin.hxx
+1
-1
No files found.
src/command/StorageCommands.cxx
View file @
5b8dce74
...
@@ -237,9 +237,14 @@ handle_mount(Client &client, Request args, Response &r)
...
@@ -237,9 +237,14 @@ handle_mount(Client &client, Request args, Response &r)
if
(
_db
!=
nullptr
&&
_db
->
IsPlugin
(
simple_db_plugin
))
{
if
(
_db
!=
nullptr
&&
_db
->
IsPlugin
(
simple_db_plugin
))
{
SimpleDatabase
&
db
=
*
(
SimpleDatabase
*
)
_db
;
SimpleDatabase
&
db
=
*
(
SimpleDatabase
*
)
_db
;
if
(
!
db
.
Mount
(
local_uri
,
remote_uri
,
error
))
{
try
{
if
(
!
db
.
Mount
(
local_uri
,
remote_uri
,
error
))
{
composite
.
Unmount
(
local_uri
);
return
print_error
(
r
,
error
);
}
}
catch
(...)
{
composite
.
Unmount
(
local_uri
);
composite
.
Unmount
(
local_uri
);
return
print_error
(
r
,
error
)
;
throw
;
}
}
// TODO: call Instance::OnDatabaseModified()?
// TODO: call Instance::OnDatabaseModified()?
...
...
src/db/plugins/simple/SimpleDatabasePlugin.cxx
View file @
5b8dce74
...
@@ -269,27 +269,21 @@ SimpleDatabase::GetSong(const char *uri, Error &error) const
...
@@ -269,27 +269,21 @@ SimpleDatabase::GetSong(const char *uri, Error &error) const
return
prefixed_light_song
;
return
prefixed_light_song
;
}
}
if
(
r
.
uri
==
nullptr
)
{
if
(
r
.
uri
==
nullptr
)
/* it's a directory */
/* it's a directory */
error
.
Format
(
db_domain
,
(
int
)
DatabaseErrorCode
::
NOT_FOUND
,
throw
DatabaseError
(
DatabaseErrorCode
::
NOT_FOUND
,
"No such song: %s"
,
uri
);
"No such song"
);
return
nullptr
;
}
if
(
strchr
(
r
.
uri
,
'/'
)
!=
nullptr
)
{
if
(
strchr
(
r
.
uri
,
'/'
)
!=
nullptr
)
/* refers to a URI "below" the actual song */
/* refers to a URI "below" the actual song */
error
.
Format
(
db_domain
,
(
int
)
DatabaseErrorCode
::
NOT_FOUND
,
throw
DatabaseError
(
DatabaseErrorCode
::
NOT_FOUND
,
"No such song: %s"
,
uri
);
"No such song"
);
return
nullptr
;
}
const
Song
*
song
=
r
.
directory
->
FindSong
(
r
.
uri
);
const
Song
*
song
=
r
.
directory
->
FindSong
(
r
.
uri
);
protect
.
unlock
();
protect
.
unlock
();
if
(
song
==
nullptr
)
{
if
(
song
==
nullptr
)
error
.
Format
(
db_domain
,
(
int
)
DatabaseErrorCode
::
NOT_FOUND
,
throw
DatabaseError
(
DatabaseErrorCode
::
NOT_FOUND
,
"No such song: %s"
,
uri
);
"No such song"
);
return
nullptr
;
}
light_song
=
song
->
Export
();
light_song
=
song
->
Export
();
...
@@ -351,9 +345,8 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
...
@@ -351,9 +345,8 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
}
}
}
}
error
.
Set
(
db_domain
,
(
int
)
DatabaseErrorCode
::
NOT_FOUND
,
throw
DatabaseError
(
DatabaseErrorCode
::
NOT_FOUND
,
"No such directory"
);
"No such directory"
);
return
false
;
}
}
bool
bool
...
@@ -421,8 +414,8 @@ SimpleDatabase::Save()
...
@@ -421,8 +414,8 @@ SimpleDatabase::Save()
mtime
=
fi
.
GetModificationTime
();
mtime
=
fi
.
GetModificationTime
();
}
}
bool
void
SimpleDatabase
::
Mount
(
const
char
*
uri
,
Database
*
db
,
Error
&
error
)
SimpleDatabase
::
Mount
(
const
char
*
uri
,
Database
*
db
)
{
{
#if !CLANG_CHECK_VERSION(3,6)
#if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */
/* disabled on clang due to -Wtautological-pointer-compare */
...
@@ -434,21 +427,16 @@ SimpleDatabase::Mount(const char *uri, Database *db, Error &error)
...
@@ -434,21 +427,16 @@ SimpleDatabase::Mount(const char *uri, Database *db, Error &error)
ScopeDatabaseLock
protect
;
ScopeDatabaseLock
protect
;
auto
r
=
root
->
LookupDirectory
(
uri
);
auto
r
=
root
->
LookupDirectory
(
uri
);
if
(
r
.
uri
==
nullptr
)
{
if
(
r
.
uri
==
nullptr
)
error
.
Format
(
db_domain
,
(
int
)
DatabaseErrorCode
::
CONFLICT
,
throw
DatabaseError
(
DatabaseErrorCode
::
CONFLICT
,
"Already exists: %s"
,
uri
);
"Already exists"
);
return
false
;
}
if
(
strchr
(
r
.
uri
,
'/'
)
!=
nullptr
)
{
if
(
strchr
(
r
.
uri
,
'/'
)
!=
nullptr
)
error
.
Format
(
db_domain
,
(
int
)
DatabaseErrorCode
::
NOT_FOUND
,
throw
DatabaseError
(
DatabaseErrorCode
::
NOT_FOUND
,
"Parent not found: %s"
,
uri
);
"Parent not found"
);
return
false
;
}
Directory
*
mnt
=
r
.
directory
->
CreateChild
(
r
.
uri
);
Directory
*
mnt
=
r
.
directory
->
CreateChild
(
r
.
uri
);
mnt
->
mounted_database
=
db
;
mnt
->
mounted_database
=
db
;
return
true
;
}
}
static
constexpr
bool
static
constexpr
bool
...
@@ -467,11 +455,9 @@ bool
...
@@ -467,11 +455,9 @@ bool
SimpleDatabase
::
Mount
(
const
char
*
local_uri
,
const
char
*
storage_uri
,
SimpleDatabase
::
Mount
(
const
char
*
local_uri
,
const
char
*
storage_uri
,
Error
&
error
)
Error
&
error
)
{
{
if
(
cache_path
.
IsNull
())
{
if
(
cache_path
.
IsNull
())
error
.
Format
(
db_domain
,
(
int
)
DatabaseErrorCode
::
NOT_FOUND
,
throw
DatabaseError
(
DatabaseErrorCode
::
NOT_FOUND
,
"No 'cache_directory' configured"
);
"No 'cache_directory' configured"
);
return
false
;
}
std
::
string
name
(
storage_uri
);
std
::
string
name
(
storage_uri
);
std
::
replace_if
(
name
.
begin
(),
name
.
end
(),
IsUnsafeChar
,
'_'
);
std
::
replace_if
(
name
.
begin
(),
name
.
end
(),
IsUnsafeChar
,
'_'
);
...
@@ -493,10 +479,12 @@ SimpleDatabase::Mount(const char *local_uri, const char *storage_uri,
...
@@ -493,10 +479,12 @@ SimpleDatabase::Mount(const char *local_uri, const char *storage_uri,
// TODO: update the new database instance?
// TODO: update the new database instance?
if
(
!
Mount
(
local_uri
,
db
,
error
))
{
try
{
Mount
(
local_uri
,
db
);
}
catch
(...)
{
db
->
Close
();
db
->
Close
();
delete
db
;
delete
db
;
return
false
;
throw
;
}
}
return
true
;
return
true
;
...
...
src/db/plugins/simple/SimpleDatabasePlugin.hxx
View file @
5b8dce74
...
@@ -97,7 +97,7 @@ public:
...
@@ -97,7 +97,7 @@ public:
* success, this object gains ownership of the given #Database
* success, this object gains ownership of the given #Database
*/
*/
gcc_nonnull_all
gcc_nonnull_all
bool
Mount
(
const
char
*
uri
,
Database
*
db
,
Error
&
error
);
void
Mount
(
const
char
*
uri
,
Database
*
db
);
gcc_nonnull_all
gcc_nonnull_all
bool
Mount
(
const
char
*
local_uri
,
const
char
*
storage_uri
,
bool
Mount
(
const
char
*
local_uri
,
const
char
*
storage_uri
,
...
...
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