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
69a42fc9
Commit
69a42fc9
authored
11 years ago
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/simple/Directory: LookupDirectory() return remaining URI
Code can now be reused in LookupSong().
parent
525789cd
sisyphus
0.23.15-alt1
0.23.14-alt1
0.23.13-alt1
0.23.12-alt1
0.23.11-alt1
0.23.8-alt3
0.23.8-alt2
0.23.8-alt1
0.21.24-alt1.1
0.21.24-alt1
0.20.23-alt3
0.20.23-alt2
0.20.23-alt1
0.20.21-alt1
0.20.15-alt1
mpd/0.20.6-alt1
mpd/0.19.9-alt1
gb-sisyphus-task339776.6100
gb-sisyphus-task337393.100
gb-sisyphus-task337176.300
gb-sisyphus-task334590.100
gb-sisyphus-task333607.100
gb-sisyphus-task331543.2500
gb-sisyphus-task328663.4700
gb-sisyphus-task325064.100
gb-sisyphus-task319111.4000
gb-sisyphus-task313704.100
gb-sisyphus-task312885.100
gb-sisyphus-task308905.3200
gb-sisyphus-task305294.500
gb-sisyphus-task304007.100
gb-sisyphus-task303674.1700
gb-sisyphus-task298681.300
gb-sisyphus-task296051.1000
gb-sisyphus-task274827.100
gb-sisyphus-task269249.2000
gb-sisyphus-task266579.400
gb-sisyphus-task258132.600
gb-sisyphus-task254601.200
gb-sisyphus-task253310.100
gb-sisyphus-task252214.300
gb-sisyphus-task251539.6100
gb-sisyphus-task247988.7000
gb-sisyphus-task238768.6000
gb-sisyphus-task229151.100
gb-sisyphus-task227574.200
gb-sisyphus-task226762.6000
gb-sisyphus-task219546.1700
gb-sisyphus-task213491.100
gb-sisyphus-task198806.100
gb-sisyphus-task181400.100
gb-sisyphus-task141957.100
gb-p9-task277538.2600
gb-c9f2-task327704.1100
No related merge requests found
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
39 deletions
+60
-39
Directory.cxx
src/db/plugins/simple/Directory.cxx
+27
-26
Directory.hxx
src/db/plugins/simple/Directory.hxx
+16
-1
SimpleDatabasePlugin.cxx
src/db/plugins/simple/SimpleDatabasePlugin.cxx
+17
-12
No files found.
src/db/plugins/simple/Directory.cxx
View file @
69a42fc9
...
...
@@ -120,38 +120,49 @@ Directory::PruneEmpty()
}
}
Directory
*
Directory
::
LookupResult
Directory
::
LookupDirectory
(
const
char
*
uri
)
{
assert
(
holding_db_lock
());
assert
(
uri
!=
nullptr
);
if
(
isRootDirectory
(
uri
))
return
this
;
return
{
this
,
nullptr
}
;
char
*
duplicated
=
xstrdup
(
uri
),
*
name
=
duplicated
;
Directory
*
d
=
this
;
while
(
1
)
{
while
(
true
)
{
char
*
slash
=
strchr
(
name
,
'/'
);
if
(
slash
==
name
)
{
d
=
nullptr
;
if
(
slash
==
name
)
break
;
}
if
(
slash
!=
nullptr
)
*
slash
=
'\0'
;
d
=
d
->
FindChild
(
name
);
if
(
d
==
nullptr
||
slash
==
nullptr
)
Directory
*
tmp
=
d
->
FindChild
(
name
);
if
(
tmp
==
nullptr
)
/* not found */
break
;
d
=
tmp
;
if
(
slash
==
nullptr
)
{
/* found everything */
name
=
nullptr
;
break
;
}
name
=
slash
+
1
;
}
free
(
duplicated
);
return
d
;
const
char
*
rest
=
name
==
nullptr
?
nullptr
:
uri
+
(
name
-
duplicated
);
return
{
d
,
rest
};
}
void
...
...
@@ -197,26 +208,16 @@ Directory::LookupSong(const char *uri)
assert
(
holding_db_lock
());
assert
(
uri
!=
nullptr
);
char
*
duplicated
=
xstrdup
(
uri
);
char
*
base
=
strrchr
(
duplicated
,
'/'
);
Directory
*
d
=
this
;
if
(
base
!=
nullptr
)
{
*
base
++
=
0
;
d
=
d
->
LookupDirectory
(
duplicated
);
if
(
d
==
nullptr
)
{
free
(
duplicated
);
auto
r
=
LookupDirectory
(
uri
);
if
(
r
.
uri
==
nullptr
)
/* it's a directory */
return
nullptr
;
}
}
else
base
=
duplicated
;
Song
*
song
=
d
->
FindSong
(
base
);
assert
(
song
==
nullptr
||
song
->
parent
==
d
);
free
(
duplicated
);
return
song
;
if
(
strchr
(
r
.
uri
,
'/'
)
!=
nullptr
)
/* refers to a URI "below" the actual song */
return
nullptr
;
return
r
.
directory
->
FindSong
(
r
.
uri
);
}
static
int
...
...
This diff is collapsed.
Click to expand it.
src/db/plugins/simple/Directory.hxx
View file @
69a42fc9
...
...
@@ -149,6 +149,21 @@ public:
return
child
;
}
struct
LookupResult
{
/**
* The last directory that was found. If the given
* URI could not be resolved at all, then this is the
* root directory.
*/
Directory
*
directory
;
/**
* The remaining URI part (without leading slash) or
* nullptr if the given URI was consumed completely.
*/
const
char
*
uri
;
};
/**
* Looks up a directory by its relative URI.
*
...
...
@@ -156,7 +171,7 @@ public:
* @return the Directory, or nullptr if none was found
*/
gcc_pure
Directory
*
LookupDirectory
(
const
char
*
uri
);
LookupResult
LookupDirectory
(
const
char
*
uri
);
gcc_pure
bool
IsEmpty
()
const
{
...
...
This diff is collapsed.
Click to expand it.
src/db/plugins/simple/SimpleDatabasePlugin.cxx
View file @
69a42fc9
...
...
@@ -244,28 +244,33 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
{
ScopeDatabaseLock
protect
;
const
Directory
*
directory
=
root
->
LookupDirectory
(
selection
.
uri
.
c_str
());
if
(
directory
==
nullptr
)
{
auto
r
=
root
->
LookupDirectory
(
selection
.
uri
.
c_str
());
if
(
r
.
uri
==
nullptr
)
{
/* it's a directory */
if
(
selection
.
recursive
&&
visit_directory
&&
!
visit_directory
(
r
.
directory
->
Export
(),
error
))
return
false
;
return
r
.
directory
->
Walk
(
selection
.
recursive
,
selection
.
filter
,
visit_directory
,
visit_song
,
visit_playlist
,
error
);
}
if
(
strchr
(
r
.
uri
,
'/'
)
==
nullptr
)
{
if
(
visit_song
)
{
Song
*
song
=
r
oot
->
LookupSong
(
selection
.
uri
.
c_str
()
);
Song
*
song
=
r
.
directory
->
FindSong
(
r
.
uri
);
if
(
song
!=
nullptr
)
{
const
LightSong
song2
=
song
->
Export
();
return
!
selection
.
Match
(
song2
)
||
visit_song
(
song2
,
error
);
}
}
error
.
Set
(
db_domain
,
DB_NOT_FOUND
,
"No such directory"
);
return
false
;
}
if
(
selection
.
recursive
&&
visit_directory
&&
!
visit_directory
(
directory
->
Export
(),
error
))
error
.
Set
(
db_domain
,
DB_NOT_FOUND
,
"No such directory"
);
return
false
;
return
directory
->
Walk
(
selection
.
recursive
,
selection
.
filter
,
visit_directory
,
visit_song
,
visit_playlist
,
error
);
}
bool
...
...
This diff is collapsed.
Click to expand it.
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