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
dd831d39
Commit
dd831d39
authored
Apr 03, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/simple: pass std::string_view to Directory::LookupDirectory()
parent
9f8dc31b
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
19 deletions
+31
-19
Uri.hxx
src/db/Uri.hxx
+8
-0
Directory.cxx
src/db/plugins/simple/Directory.cxx
+3
-4
Directory.hxx
src/db/plugins/simple/Directory.hxx
+3
-3
SimpleDatabasePlugin.cxx
src/db/plugins/simple/SimpleDatabasePlugin.cxx
+13
-10
Service.cxx
src/db/update/Service.cxx
+4
-2
No files found.
src/db/Uri.hxx
View file @
dd831d39
...
...
@@ -20,10 +20,18 @@
#ifndef MPD_DB_URI_HXX
#define MPD_DB_URI_HXX
#include <string_view>
static
inline
bool
isRootDirectory
(
const
char
*
name
)
{
return
name
[
0
]
==
0
||
(
name
[
0
]
==
'/'
&&
name
[
1
]
==
0
);
}
static
inline
bool
isRootDirectory
(
std
::
string_view
name
)
noexcept
{
return
name
.
empty
()
||
(
name
.
size
()
==
1
&&
name
.
front
()
==
'/'
);
}
#endif
src/db/plugins/simple/Directory.cxx
View file @
dd831d39
...
...
@@ -127,13 +127,12 @@ Directory::PruneEmpty() noexcept
}
Directory
::
LookupResult
Directory
::
LookupDirectory
(
const
char
*
_uri
)
noexcept
Directory
::
LookupDirectory
(
std
::
string_view
_uri
)
noexcept
{
assert
(
holding_db_lock
());
assert
(
_uri
!=
nullptr
);
if
(
isRootDirectory
(
_uri
))
return
{
this
,
_uri
,
nullptr
};
return
{
this
,
_uri
,
{}
};
StringView
uri
(
_uri
);
...
...
@@ -156,7 +155,7 @@ Directory::LookupDirectory(const char *_uri) noexcept
uri
=
rest
;
}
while
(
uri
!=
nullptr
);
return
{
d
,
StringView
(
_uri
,
uri
.
data
-
1
),
uri
.
data
};
return
{
d
,
_uri
.
substr
(
0
,
uri
.
data
-
_uri
.
data
()),
uri
};
}
void
...
...
src/db/plugins/simple/Directory.hxx
View file @
dd831d39
...
...
@@ -189,9 +189,9 @@ public:
/**
* The remaining URI part (without leading slash) or
*
nullptr
if the given URI was consumed completely.
*
empty
if the given URI was consumed completely.
*/
const
char
*
rest
;
std
::
string_view
rest
;
};
/**
...
...
@@ -201,7 +201,7 @@ public:
* @return the Directory, or nullptr if none was found
*/
gcc_pure
LookupResult
LookupDirectory
(
const
char
*
uri
)
noexcept
;
LookupResult
LookupDirectory
(
std
::
string_view
uri
)
noexcept
;
gcc_pure
bool
IsEmpty
()
const
noexcept
{
...
...
src/db/plugins/simple/SimpleDatabasePlugin.cxx
View file @
dd831d39
...
...
@@ -211,8 +211,10 @@ SimpleDatabase::GetSong(const char *uri) const
/* pass the request to the mounted database */
protect
.
unlock
();
/* note: r.rest.data() is actually null-terminated
because it points inside the "uri" parameter */
const
LightSong
*
song
=
r
.
directory
->
mounted_database
->
GetSong
(
r
.
rest
);
r
.
directory
->
mounted_database
->
GetSong
(
r
.
rest
.
data
()
);
if
(
song
==
nullptr
)
return
nullptr
;
...
...
@@ -222,12 +224,12 @@ SimpleDatabase::GetSong(const char *uri) const
return
prefixed_light_song
;
}
if
(
r
.
rest
==
nullptr
)
if
(
r
.
rest
.
data
()
==
nullptr
)
/* it's a directory */
throw
DatabaseError
(
DatabaseErrorCode
::
NOT_FOUND
,
"No such song"
);
if
(
strchr
(
r
.
rest
,
'/'
)
!=
nullptr
)
if
(
r
.
rest
.
find
(
'/'
)
!=
std
::
string_view
::
npos
)
/* refers to a URI "below" the actual song */
throw
DatabaseError
(
DatabaseErrorCode
::
NOT_FOUND
,
"No such song"
);
...
...
@@ -283,14 +285,15 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
{
ScopeDatabaseLock
protect
;
auto
r
=
root
->
LookupDirectory
(
selection
.
uri
.
c_str
()
);
auto
r
=
root
->
LookupDirectory
(
selection
.
uri
);
if
(
r
.
directory
->
IsMount
())
{
/* pass the request and the remaining uri to the mounted database */
protect
.
unlock
();
WalkMount
(
r
.
uri
,
*
(
r
.
directory
->
mounted_database
),
(
r
.
rest
==
nullptr
)
?
""
:
r
.
rest
,
selection
,
r
.
rest
,
selection
,
visit_directory
,
visit_song
,
visit_playlist
);
return
;
...
...
@@ -298,7 +301,7 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
DatabaseVisitorHelper
helper
(
CheckSelection
(
selection
),
visit_song
);
if
(
r
.
rest
==
nullptr
)
{
if
(
r
.
rest
.
data
()
==
nullptr
)
{
/* it's a directory */
if
(
selection
.
recursive
&&
visit_directory
)
...
...
@@ -311,7 +314,7 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
return
;
}
if
(
strchr
(
r
.
rest
,
'/'
)
==
nullptr
)
{
if
(
r
.
rest
.
find
(
'/'
)
==
std
::
string_view
::
npos
)
{
if
(
visit_song
)
{
Song
*
song
=
r
.
directory
->
FindSong
(
r
.
rest
);
if
(
song
!=
nullptr
)
{
...
...
@@ -402,11 +405,11 @@ SimpleDatabase::Mount(const char *uri, DatabasePtr db)
ScopeDatabaseLock
protect
;
auto
r
=
root
->
LookupDirectory
(
uri
);
if
(
r
.
rest
==
nullptr
)
if
(
r
.
rest
.
data
()
==
nullptr
)
throw
DatabaseError
(
DatabaseErrorCode
::
CONFLICT
,
"Already exists"
);
if
(
strchr
(
r
.
rest
,
'/'
)
!=
nullptr
)
if
(
r
.
rest
.
find
(
'/'
)
!=
std
::
string_view
::
npos
)
throw
DatabaseError
(
DatabaseErrorCode
::
NOT_FOUND
,
"Parent not found"
);
...
...
@@ -461,7 +464,7 @@ SimpleDatabase::LockUmountSteal(const char *uri) noexcept
ScopeDatabaseLock
protect
;
auto
r
=
root
->
LookupDirectory
(
uri
);
if
(
r
.
rest
!=
nullptr
||
!
r
.
directory
->
IsMount
())
if
(
r
.
rest
.
data
()
!=
nullptr
||
!
r
.
directory
->
IsMount
())
return
nullptr
;
auto
db
=
std
::
move
(
r
.
directory
->
mounted_database
);
...
...
src/db/update/Service.cxx
View file @
dd831d39
...
...
@@ -169,7 +169,7 @@ UpdateService::GenerateId() noexcept
}
unsigned
UpdateService
::
Enqueue
(
const
char
*
path
,
bool
discard
)
UpdateService
::
Enqueue
(
const
char
*
_
path
,
bool
discard
)
{
assert
(
GetEventLoop
().
IsInside
());
...
...
@@ -178,6 +178,8 @@ UpdateService::Enqueue(const char *path, bool discard)
SimpleDatabase
*
db2
;
Storage
*
storage2
;
std
::
string_view
path
(
_path
);
Directory
::
LookupResult
lr
;
{
const
ScopeDatabaseLock
protect
;
...
...
@@ -192,7 +194,7 @@ UpdateService::Enqueue(const char *path, bool discard)
if
(
db2
==
nullptr
)
throw
std
::
runtime_error
(
"Cannot update this type of database"
);
if
(
lr
.
rest
==
nullptr
)
{
if
(
lr
.
rest
.
data
()
==
nullptr
)
{
storage2
=
storage
.
GetMount
(
path
);
path
=
""
;
}
else
{
...
...
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