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)
if
(
_db
!=
nullptr
&&
_db
->
IsPlugin
(
simple_db_plugin
))
{
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
);
return
print_error
(
r
,
error
)
;
throw
;
}
// 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
return
prefixed_light_song
;
}
if
(
r
.
uri
==
nullptr
)
{
if
(
r
.
uri
==
nullptr
)
/* it's a directory */
error
.
Format
(
db_domain
,
(
int
)
DatabaseErrorCode
::
NOT_FOUND
,
"No such song: %s"
,
uri
);
return
nullptr
;
}
throw
DatabaseError
(
DatabaseErrorCode
::
NOT_FOUND
,
"No such song"
);
if
(
strchr
(
r
.
uri
,
'/'
)
!=
nullptr
)
{
if
(
strchr
(
r
.
uri
,
'/'
)
!=
nullptr
)
/* refers to a URI "below" the actual song */
error
.
Format
(
db_domain
,
(
int
)
DatabaseErrorCode
::
NOT_FOUND
,
"No such song: %s"
,
uri
);
return
nullptr
;
}
throw
DatabaseError
(
DatabaseErrorCode
::
NOT_FOUND
,
"No such song"
);
const
Song
*
song
=
r
.
directory
->
FindSong
(
r
.
uri
);
protect
.
unlock
();
if
(
song
==
nullptr
)
{
error
.
Format
(
db_domain
,
(
int
)
DatabaseErrorCode
::
NOT_FOUND
,
"No such song: %s"
,
uri
);
return
nullptr
;
}
if
(
song
==
nullptr
)
throw
DatabaseError
(
DatabaseErrorCode
::
NOT_FOUND
,
"No such song"
);
light_song
=
song
->
Export
();
...
...
@@ -351,9 +345,8 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
}
}
error
.
Set
(
db_domain
,
(
int
)
DatabaseErrorCode
::
NOT_FOUND
,
"No such directory"
);
return
false
;
throw
DatabaseError
(
DatabaseErrorCode
::
NOT_FOUND
,
"No such directory"
);
}
bool
...
...
@@ -421,8 +414,8 @@ SimpleDatabase::Save()
mtime
=
fi
.
GetModificationTime
();
}
bool
SimpleDatabase
::
Mount
(
const
char
*
uri
,
Database
*
db
,
Error
&
error
)
void
SimpleDatabase
::
Mount
(
const
char
*
uri
,
Database
*
db
)
{
#if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */
...
...
@@ -434,21 +427,16 @@ SimpleDatabase::Mount(const char *uri, Database *db, Error &error)
ScopeDatabaseLock
protect
;
auto
r
=
root
->
LookupDirectory
(
uri
);
if
(
r
.
uri
==
nullptr
)
{
error
.
Format
(
db_domain
,
(
int
)
DatabaseErrorCode
::
CONFLICT
,
"Already exists: %s"
,
uri
);
return
false
;
}
if
(
r
.
uri
==
nullptr
)
throw
DatabaseError
(
DatabaseErrorCode
::
CONFLICT
,
"Already exists"
);
if
(
strchr
(
r
.
uri
,
'/'
)
!=
nullptr
)
{
error
.
Format
(
db_domain
,
(
int
)
DatabaseErrorCode
::
NOT_FOUND
,
"Parent not found: %s"
,
uri
);
return
false
;
}
if
(
strchr
(
r
.
uri
,
'/'
)
!=
nullptr
)
throw
DatabaseError
(
DatabaseErrorCode
::
NOT_FOUND
,
"Parent not found"
);
Directory
*
mnt
=
r
.
directory
->
CreateChild
(
r
.
uri
);
mnt
->
mounted_database
=
db
;
return
true
;
}
static
constexpr
bool
...
...
@@ -467,11 +455,9 @@ bool
SimpleDatabase
::
Mount
(
const
char
*
local_uri
,
const
char
*
storage_uri
,
Error
&
error
)
{
if
(
cache_path
.
IsNull
())
{
error
.
Format
(
db_domain
,
(
int
)
DatabaseErrorCode
::
NOT_FOUND
,
"No 'cache_directory' configured"
);
return
false
;
}
if
(
cache_path
.
IsNull
())
throw
DatabaseError
(
DatabaseErrorCode
::
NOT_FOUND
,
"No 'cache_directory' configured"
);
std
::
string
name
(
storage_uri
);
std
::
replace_if
(
name
.
begin
(),
name
.
end
(),
IsUnsafeChar
,
'_'
);
...
...
@@ -493,10 +479,12 @@ SimpleDatabase::Mount(const char *local_uri, const char *storage_uri,
// TODO: update the new database instance?
if
(
!
Mount
(
local_uri
,
db
,
error
))
{
try
{
Mount
(
local_uri
,
db
);
}
catch
(...)
{
db
->
Close
();
delete
db
;
return
false
;
throw
;
}
return
true
;
...
...
src/db/plugins/simple/SimpleDatabasePlugin.hxx
View file @
5b8dce74
...
...
@@ -97,7 +97,7 @@ public:
* success, this object gains ownership of the given #Database
*/
gcc_nonnull_all
bool
Mount
(
const
char
*
uri
,
Database
*
db
,
Error
&
error
);
void
Mount
(
const
char
*
uri
,
Database
*
db
);
gcc_nonnull_all
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