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
2b965a54
Commit
2b965a54
authored
Oct 07, 2008
by
Eric Wong
Committed by
Max Kellermann
Oct 07, 2008
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
directory: use songvec_for_each for iterators
Get rid of songvec_write so we can enforce proper locking
parent
c47f97e1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
28 deletions
+30
-28
directory.c
src/directory.c
+30
-28
No files found.
src/directory.c
View file @
2b965a54
...
...
@@ -278,15 +278,34 @@ static int skip_path(const char *path)
return
(
path
[
0
]
==
'.'
||
strchr
(
path
,
'\n'
))
?
1
:
0
;
}
struct
delete_data
{
char
*
tmp
;
Directory
*
dir
;
enum
update_return
ret
;
};
/* passed to songvec_for_each */
static
int
delete_song_if_removed
(
Song
*
song
,
void
*
_data
)
{
struct
delete_data
*
data
=
_data
;
data
->
tmp
=
get_song_url
(
data
->
tmp
,
song
);
assert
(
data
->
tmp
);
if
(
!
isFile
(
data
->
tmp
,
NULL
))
{
delete_song
(
data
->
dir
,
song
);
data
->
ret
=
UPDATE_RETURN_UPDATED
;
}
return
0
;
}
static
enum
update_return
removeDeletedFromDirectory
(
char
*
path_max_tmp
,
Directory
*
directory
)
{
const
char
*
dirname
=
(
directory
&&
directory
->
path
)
?
directory
->
path
:
NULL
;
enum
update_return
ret
=
UPDATE_RETURN_NOUPDATE
;
int
i
;
struct
songvec
*
sv
=
&
directory
->
songs
;
struct
dirvec
*
dv
=
&
directory
->
children
;
struct
delete_data
data
;
for
(
i
=
dv
->
nr
;
--
i
>=
0
;
)
{
if
(
isDir
(
dv
->
base
[
i
]
->
path
))
...
...
@@ -296,23 +315,12 @@ removeDeletedFromDirectory(char *path_max_tmp, Directory * directory)
ret
=
UPDATE_RETURN_UPDATED
;
}
for
(
i
=
sv
->
nr
;
--
i
>=
0
;
)
{
/* cleaner deletes if we go backwards */
Song
*
song
=
sv
->
base
[
i
];
assert
(
song
);
assert
(
*
song
->
url
);
if
(
dirname
)
sprintf
(
path_max_tmp
,
"%s/%s"
,
dirname
,
song
->
url
);
else
strcpy
(
path_max_tmp
,
song
->
url
);
if
(
!
isFile
(
path_max_tmp
,
NULL
))
{
delete_song
(
directory
,
song
);
ret
=
UPDATE_RETURN_UPDATED
;
}
}
data
.
dir
=
directory
;
data
.
tmp
=
path_max_tmp
;
data
.
ret
=
UPDATE_RETURN_UPDATED
;
songvec_for_each
(
&
directory
->
songs
,
delete_song_if_removed
,
&
data
);
return
ret
;
return
data
.
ret
;
}
static
Directory
*
addDirectoryPathToDB
(
const
char
*
utf8path
)
...
...
@@ -981,15 +989,9 @@ static int traverseAllInSubDirectory(Directory * directory,
return
err
;
if
(
forEachSong
)
{
int
i
;
struct
songvec
*
sv
=
&
directory
->
songs
;
Song
**
sp
=
sv
->
base
;
for
(
i
=
sv
->
nr
;
--
i
>=
0
;
)
{
Song
*
song
=
*
sp
++
;
if
((
err
=
forEachSong
(
song
,
data
))
<
0
)
return
err
;
}
err
=
songvec_for_each
(
&
directory
->
songs
,
forEachSong
,
data
);
if
(
err
<
0
)
return
err
;
}
for
(
j
=
0
;
err
>=
0
&&
j
<
dv
->
nr
;
++
j
)
...
...
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