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
bda77ffc
Commit
bda77ffc
authored
Nov 19, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/Interface: remove IsPlugin(), use `dynamic_cast` instead
parent
ed9ece5e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
30 deletions
+15
-30
Main.cxx
src/Main.cxx
+4
-4
StorageCommands.cxx
src/command/StorageCommands.cxx
+4
-10
Interface.hxx
src/db/Interface.hxx
+0
-4
Service.cxx
src/db/update/Service.cxx
+5
-9
StorageState.cxx
src/storage/StorageState.cxx
+2
-3
No files found.
src/Main.cxx
View file @
bda77ffc
...
...
@@ -216,17 +216,17 @@ glue_db_init_and_load(const ConfigData &config)
std
::
throw_with_nested
(
std
::
runtime_error
(
"Failed to open database plugin"
));
}
if
(
!
instance
->
database
->
IsPlugin
(
simple_db_plugin
))
auto
*
db
=
dynamic_cast
<
SimpleDatabase
*>
(
instance
->
database
);
if
(
db
==
nullptr
)
return
true
;
SimpleDatabase
&
db
=
*
(
SimpleDatabase
*
)
instance
->
database
;
instance
->
update
=
new
UpdateService
(
config
,
instance
->
event_loop
,
db
,
instance
->
event_loop
,
*
db
,
static_cast
<
CompositeStorage
&>
(
*
instance
->
storage
),
*
instance
);
/* run database update after daemonization? */
return
db
.
FileExists
();
return
db
->
FileExists
();
}
static
bool
...
...
src/command/StorageCommands.cxx
View file @
bda77ffc
...
...
@@ -209,12 +209,9 @@ handle_mount(Client &client, Request args, Response &r)
instance
.
EmitIdle
(
IDLE_MOUNT
);
#ifdef ENABLE_DATABASE
Database
*
_db
=
instance
.
database
;
if
(
_db
!=
nullptr
&&
_db
->
IsPlugin
(
simple_db_plugin
))
{
SimpleDatabase
&
db
=
*
(
SimpleDatabase
*
)
_db
;
if
(
auto
*
db
=
dynamic_cast
<
SimpleDatabase
*>
(
instance
.
database
))
{
try
{
db
.
Mount
(
local_uri
,
remote_uri
);
db
->
Mount
(
local_uri
,
remote_uri
);
}
catch
(...)
{
composite
.
Unmount
(
local_uri
);
throw
;
...
...
@@ -256,11 +253,8 @@ handle_unmount(Client &client, Request args, Response &r)
destroy here */
instance
.
update
->
CancelMount
(
local_uri
);
Database
*
_db
=
instance
.
database
;
if
(
_db
!=
nullptr
&&
_db
->
IsPlugin
(
simple_db_plugin
))
{
SimpleDatabase
&
db
=
*
(
SimpleDatabase
*
)
_db
;
if
(
db
.
Unmount
(
local_uri
))
if
(
auto
*
db
=
dynamic_cast
<
SimpleDatabase
*>
(
instance
.
database
))
{
if
(
db
->
Unmount
(
local_uri
))
// TODO: call Instance::OnDatabaseModified()?
instance
.
EmitIdle
(
IDLE_DATABASE
);
}
...
...
src/db/Interface.hxx
View file @
bda77ffc
...
...
@@ -52,10 +52,6 @@ public:
return
plugin
;
}
bool
IsPlugin
(
const
DatabasePlugin
&
other
)
const
noexcept
{
return
&
plugin
==
&
other
;
}
/**
* Open the database. Read it into memory if applicable.
*
...
...
src/db/update/Service.cxx
View file @
bda77ffc
...
...
@@ -94,11 +94,9 @@ UpdateService::CancelMount(const char *uri)
cancel_current
=
next
.
IsDefined
()
&&
next
.
storage
==
storage2
;
}
Database
&
_db2
=
*
lr
.
directory
->
mounted_database
;
if
(
_db2
.
IsPlugin
(
simple_db_plugin
))
{
SimpleDatabase
&
db2
=
static_cast
<
SimpleDatabase
&>
(
_db2
);
queue
.
Erase
(
db2
);
cancel_current
|=
next
.
IsDefined
()
&&
next
.
db
==
&
db2
;
if
(
auto
*
db2
=
dynamic_cast
<
SimpleDatabase
*>
(
lr
.
directory
->
mounted_database
))
{
queue
.
Erase
(
*
db2
);
cancel_current
|=
next
.
IsDefined
()
&&
next
.
db
==
db2
;
}
if
(
cancel_current
&&
walk
!=
nullptr
)
{
...
...
@@ -190,12 +188,10 @@ UpdateService::Enqueue(const char *path, bool discard)
/* follow the mountpoint, update the mounted
database */
Database
&
_db2
=
*
lr
.
directory
->
mounted_database
;
if
(
!
_db2
.
IsPlugin
(
simple_db_plugin
)
)
db2
=
dynamic_cast
<
SimpleDatabase
*>
(
lr
.
directory
->
mounted_database
)
;
if
(
db2
==
nullptr
)
throw
std
::
runtime_error
(
"Cannot update this type of database"
);
db2
=
static_cast
<
SimpleDatabase
*>
(
&
_db2
);
if
(
lr
.
uri
==
nullptr
)
{
storage2
=
storage
.
GetMount
(
path
);
path
=
""
;
...
...
src/storage/StorageState.cxx
View file @
bda77ffc
...
...
@@ -106,10 +106,9 @@ storage_state_restore(const char *line, TextFile &file, Instance &instance)
return
true
;
}
Database
*
db
=
instance
.
database
;
if
(
db
!=
nullptr
&&
db
->
IsPlugin
(
simple_db_plugin
))
{
if
(
auto
*
db
=
dynamic_cast
<
SimpleDatabase
*>
(
instance
.
database
))
{
try
{
((
SimpleDatabase
*
)
db
)
->
Mount
(
uri
.
c_str
(),
url
.
c_str
());
db
->
Mount
(
uri
.
c_str
(),
url
.
c_str
());
}
catch
(...)
{
FormatError
(
std
::
current_exception
(),
"Failed to restore mount to %s"
,
...
...
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