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
dcd483bd
Commit
dcd483bd
authored
Jan 02, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage/Composite: use std::unique_ptr<Storage>
parent
3c5e4e27
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
12 additions
and
23 deletions
+12
-23
Main.cxx
src/Main.cxx
+1
-1
StorageCommands.cxx
src/command/StorageCommands.cxx
+1
-1
CompositeStorage.cxx
src/storage/CompositeStorage.cxx
+4
-12
CompositeStorage.hxx
src/storage/CompositeStorage.hxx
+5
-8
StorageState.cxx
src/storage/StorageState.cxx
+1
-1
No files found.
src/Main.cxx
View file @
dcd483bd
...
...
@@ -181,7 +181,7 @@ InitStorage(EventLoop &event_loop)
CompositeStorage
*
composite
=
new
CompositeStorage
();
instance
->
storage
=
composite
;
composite
->
Mount
(
""
,
st
orage
.
release
(
));
composite
->
Mount
(
""
,
st
d
::
move
(
storage
));
}
/**
...
...
src/command/StorageCommands.cxx
View file @
dcd483bd
...
...
@@ -205,7 +205,7 @@ handle_mount(Client &client, Request args, Response &r)
return
CommandResult
::
ERROR
;
}
composite
.
Mount
(
local_uri
,
st
orage
.
release
(
));
composite
.
Mount
(
local_uri
,
st
d
::
move
(
storage
));
instance
.
EmitIdle
(
IDLE_MOUNT
);
#ifdef ENABLE_DATABASE
...
...
src/storage/CompositeStorage.cxx
View file @
dcd483bd
...
...
@@ -103,11 +103,6 @@ NextSegment(const char *&uri_r)
}
}
CompositeStorage
::
Directory
::~
Directory
()
{
delete
storage
;
}
const
CompositeStorage
::
Directory
*
CompositeStorage
::
Directory
::
Find
(
const
char
*
uri
)
const
noexcept
{
...
...
@@ -144,8 +139,7 @@ CompositeStorage::Directory::Unmount() noexcept
if
(
storage
==
nullptr
)
return
false
;
delete
storage
;
storage
=
nullptr
;
storage
.
reset
();
return
true
;
}
...
...
@@ -210,18 +204,16 @@ CompositeStorage::GetMount(const char *uri) noexcept
/* not a mount point */
return
nullptr
;
return
result
.
directory
->
storage
;
return
result
.
directory
->
storage
.
get
()
;
}
void
CompositeStorage
::
Mount
(
const
char
*
uri
,
Storage
*
storage
)
CompositeStorage
::
Mount
(
const
char
*
uri
,
std
::
unique_ptr
<
Storage
>
storage
)
{
const
std
::
lock_guard
<
Mutex
>
protect
(
mutex
);
Directory
&
directory
=
root
.
Make
(
uri
);
if
(
directory
.
storage
!=
nullptr
)
delete
directory
.
storage
;
directory
.
storage
=
storage
;
directory
.
storage
=
std
::
move
(
storage
);
}
bool
...
...
src/storage/CompositeStorage.hxx
View file @
dcd483bd
...
...
@@ -25,6 +25,7 @@
#include "thread/Mutex.hxx"
#include "Compiler.h"
#include <memory>
#include <string>
#include <map>
...
...
@@ -47,13 +48,10 @@ class CompositeStorage final : public Storage {
* Other Directory instances may have one, and child
* mounts will be "mixed" in.
*/
Storage
*
storage
;
std
::
unique_ptr
<
Storage
>
storage
;
std
::
map
<
std
::
string
,
Directory
>
children
;
Directory
()
:
storage
(
nullptr
)
{}
~
Directory
();
gcc_pure
bool
IsEmpty
()
const
noexcept
{
return
storage
==
nullptr
&&
children
.
empty
();
...
...
@@ -115,7 +113,7 @@ public:
VisitMounts
(
uri
,
root
,
t
);
}
void
Mount
(
const
char
*
uri
,
Storage
*
storage
);
void
Mount
(
const
char
*
uri
,
std
::
unique_ptr
<
Storage
>
storage
);
bool
Unmount
(
const
char
*
uri
);
/* virtual methods from class Storage */
...
...
@@ -133,9 +131,8 @@ private:
template
<
typename
T
>
void
VisitMounts
(
std
::
string
&
uri
,
const
Directory
&
directory
,
T
t
)
const
{
const
Storage
*
const
storage
=
directory
.
storage
;
if
(
storage
!=
nullptr
)
t
(
uri
.
c_str
(),
*
storage
);
if
(
directory
.
storage
)
t
(
uri
.
c_str
(),
*
directory
.
storage
);
if
(
!
uri
.
empty
())
uri
.
push_back
(
'/'
);
...
...
src/storage/StorageState.cxx
View file @
dcd483bd
...
...
@@ -120,7 +120,7 @@ storage_state_restore(const char *line, TextFile &file, Instance &instance)
}
((
CompositeStorage
*
)
instance
.
storage
)
->
Mount
(
uri
.
c_str
(),
st
orage
.
release
(
));
st
d
::
move
(
storage
));
return
true
;
}
...
...
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