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
3c759633
Commit
3c759633
authored
Jan 24, 2012
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
directory: add function directory_get_song(), ...
Wrap songvec_find() and other songvec methods.
parent
5f9dd828
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
14 deletions
+64
-14
directory.c
src/directory.c
+32
-2
directory.h
src/directory.h
+22
-0
directory_save.c
src/directory_save.c
+2
-2
update_walk.c
src/update_walk.c
+8
-10
No files found.
src/directory.c
View file @
3c759633
...
...
@@ -177,11 +177,41 @@ directory_lookup_directory(struct directory *directory, const char *uri)
return
found
;
}
void
directory_add_song
(
struct
directory
*
directory
,
struct
song
*
song
)
{
assert
(
directory
!=
NULL
);
assert
(
song
!=
NULL
);
assert
(
song
->
parent
==
directory
);
songvec_add
(
&
directory
->
songs
,
song
);
}
void
directory_remove_song
(
struct
directory
*
directory
,
struct
song
*
song
)
{
assert
(
directory
!=
NULL
);
assert
(
song
!=
NULL
);
assert
(
song
->
parent
==
directory
);
songvec_delete
(
&
directory
->
songs
,
song
);
}
struct
song
*
directory_get_song
(
const
struct
directory
*
directory
,
const
char
*
name_utf8
)
{
assert
(
directory
!=
NULL
);
assert
(
name_utf8
!=
NULL
);
struct
song
*
song
=
songvec_find
(
&
directory
->
songs
,
name_utf8
);
assert
(
song
==
NULL
||
song
->
parent
==
directory
);
return
song
;
}
struct
song
*
directory_lookup_song
(
struct
directory
*
directory
,
const
char
*
uri
)
{
char
*
duplicated
,
*
base
;
struct
song
*
song
;
assert
(
directory
!=
NULL
);
assert
(
uri
!=
NULL
);
...
...
@@ -199,7 +229,7 @@ directory_lookup_song(struct directory *directory, const char *uri)
}
else
base
=
duplicated
;
s
ong
=
songvec_find
(
&
directory
->
songs
,
base
);
s
truct
song
*
song
=
directory_get_song
(
directory
,
base
);
assert
(
song
==
NULL
||
song
->
parent
==
directory
);
g_free
(
duplicated
);
...
...
src/directory.h
View file @
3c759633
...
...
@@ -181,6 +181,28 @@ struct directory *
directory_lookup_directory
(
struct
directory
*
directory
,
const
char
*
uri
);
/**
* Add a song object to this directory. Its "parent" attribute must
* be set already.
*/
void
directory_add_song
(
struct
directory
*
directory
,
struct
song
*
song
);
/**
* Remove a song object from this directory (which effectively
* invalidates the song object, because the "parent" attribute becomes
* stale), but does not free it.
*/
void
directory_remove_song
(
struct
directory
*
directory
,
struct
song
*
song
);
/**
* Look up a song in this directory by its name.
*/
G_GNUC_PURE
struct
song
*
directory_get_song
(
const
struct
directory
*
directory
,
const
char
*
name_utf8
);
/**
* Looks up a song by its relative URI.
*
* @param directory the parent (or grandparent, ...) directory
...
...
src/directory_save.c
View file @
3c759633
...
...
@@ -146,7 +146,7 @@ directory_load(FILE *fp, struct directory *directory,
const
char
*
name
=
line
+
sizeof
(
SONG_BEGIN
)
-
1
;
struct
song
*
song
;
if
(
songvec_find
(
&
directory
->
songs
,
name
)
!=
NULL
)
{
if
(
directory_get_song
(
directory
,
name
)
!=
NULL
)
{
g_set_error
(
error
,
directory_quark
(),
0
,
"Duplicate song '%s'"
,
name
);
return
NULL
;
...
...
@@ -157,7 +157,7 @@ directory_load(FILE *fp, struct directory *directory,
if
(
song
==
NULL
)
return
false
;
songvec_add
(
&
directory
->
songs
,
song
);
directory_add_song
(
directory
,
song
);
}
else
if
(
g_str_has_prefix
(
line
,
PLAYLIST_META_BEGIN
))
{
/* duplicate the name, because
playlist_metadata_load() will overwrite the
...
...
src/update_walk.c
View file @
3c759633
...
...
@@ -93,7 +93,7 @@ static void
delete_song
(
struct
directory
*
dir
,
struct
song
*
del
)
{
/* first, prevent traversers in main task from getting this */
songvec_delete
(
&
dir
->
songs
,
del
);
directory_remove_song
(
dir
,
del
);
/* now take it out of the playlist (in the main_task) */
update_remove_song
(
del
);
...
...
@@ -144,13 +144,13 @@ static void
delete_name_in
(
struct
directory
*
parent
,
const
char
*
name
)
{
struct
directory
*
directory
=
directory_get_child
(
parent
,
name
);
struct
song
*
song
=
songvec_find
(
&
parent
->
songs
,
name
);
if
(
directory
!=
NULL
)
{
delete_directory
(
directory
);
modified
=
true
;
}
struct
song
*
song
=
directory_get_song
(
parent
,
name
);
if
(
song
!=
NULL
)
{
delete_song
(
parent
,
song
);
modified
=
true
;
...
...
@@ -357,7 +357,6 @@ static void
update_archive_tree
(
struct
directory
*
directory
,
char
*
name
)
{
struct
directory
*
subdir
;
struct
song
*
song
;
char
*
tmp
;
tmp
=
strchr
(
name
,
'/'
);
...
...
@@ -377,11 +376,11 @@ update_archive_tree(struct directory *directory, char *name)
return
;
}
//add file
s
ong
=
songvec_find
(
&
directory
->
songs
,
name
);
s
truct
song
*
song
=
directory_get_song
(
directory
,
name
);
if
(
song
==
NULL
)
{
song
=
song_file_load
(
name
,
directory
);
if
(
song
!=
NULL
)
{
songvec_add
(
&
directory
->
songs
,
song
);
directory_add_song
(
directory
,
song
);
modified
=
true
;
g_message
(
"added %s/%s"
,
directory_get_path
(
directory
),
name
);
...
...
@@ -499,7 +498,7 @@ update_container_file( struct directory* directory,
song
->
tag
=
plugin
->
tag_dup
(
child_path_fs
);
g_free
(
child_path_fs
);
songvec_add
(
&
contdir
->
songs
,
song
);
directory_add_song
(
contdir
,
song
);
modified
=
true
;
...
...
@@ -559,7 +558,7 @@ update_regular_file(struct directory *directory,
if
((
plugin
=
decoder_plugin_from_suffix
(
suffix
,
false
))
!=
NULL
)
{
struct
song
*
song
=
songvec_find
(
&
directory
->
songs
,
name
);
struct
song
*
song
=
directory_get_song
(
directory
,
name
);
if
(
!
directory_child_access
(
directory
,
name
,
R_OK
))
{
g_warning
(
"no read permissions on %s/%s"
,
...
...
@@ -592,7 +591,7 @@ update_regular_file(struct directory *directory,
return
;
}
songvec_add
(
&
directory
->
songs
,
song
);
directory_add_song
(
directory
,
song
);
modified
=
true
;
g_message
(
"added %s/%s"
,
directory_get_path
(
directory
),
name
);
...
...
@@ -800,7 +799,6 @@ directory_make_child_checked(struct directory *parent, const char *name_utf8)
{
struct
directory
*
directory
;
struct
stat
st
;
struct
song
*
conflicting
;
directory
=
directory_get_child
(
parent
,
name_utf8
);
if
(
directory
!=
NULL
)
...
...
@@ -812,7 +810,7 @@ directory_make_child_checked(struct directory *parent, const char *name_utf8)
/* if we're adding directory paths, make sure to delete filenames
with potentially the same name */
conflicting
=
songvec_find
(
&
parent
->
songs
,
name_utf8
);
struct
song
*
conflicting
=
directory_get_song
(
parent
,
name_utf8
);
if
(
conflicting
)
delete_song
(
parent
,
conflicting
);
...
...
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