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
4fdcc049
Commit
4fdcc049
authored
Feb 12, 2012
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update_walk: move code to update_db.c
parent
0c4a2bea
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
160 additions
and
85 deletions
+160
-85
Makefile.am
Makefile.am
+1
-0
update_db.c
src/update_db.c
+103
-0
update_db.h
src/update_db.h
+52
-0
update_walk.c
src/update_walk.c
+4
-85
No files found.
Makefile.am
View file @
4fdcc049
...
...
@@ -266,6 +266,7 @@ src_mpd_SOURCES = \
src/update.c
\
src/update_queue.c
\
src/update_io.c src/update_io.h
\
src/update_db.c src/update_db.h
\
src/update_walk.c
\
src/update_remove.c
\
src/client.c
\
...
...
src/update_db.c
0 → 100644
View file @
4fdcc049
/*
* Copyright (C) 2003-2012 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
/* must be first for large file support */
#include "update_db.h"
#include "update_internal.h"
#include "directory.h"
#include "song.h"
#include "db_lock.h"
#include <glib.h>
#include <assert.h>
void
delete_song
(
struct
directory
*
dir
,
struct
song
*
del
)
{
assert
(
del
->
parent
==
dir
);
/* first, prevent traversers in main task from getting this */
directory_remove_song
(
dir
,
del
);
db_unlock
();
/* temporary unlock, because update_remove_song() blocks */
/* now take it out of the playlist (in the main_task) */
update_remove_song
(
del
);
/* finally, all possible references gone, free it */
song_free
(
del
);
db_lock
();
}
/**
* Recursively remove all sub directories and songs from a directory,
* leaving an empty directory.
*
* Caller must lock the #db_mutex.
*/
static
void
clear_directory
(
struct
directory
*
directory
)
{
struct
directory
*
child
,
*
n
;
directory_for_each_child_safe
(
child
,
n
,
directory
)
delete_directory
(
child
);
struct
song
*
song
,
*
ns
;
directory_for_each_song_safe
(
song
,
ns
,
directory
)
{
assert
(
song
->
parent
==
directory
);
delete_song
(
directory
,
song
);
}
}
void
delete_directory
(
struct
directory
*
directory
)
{
assert
(
directory
->
parent
!=
NULL
);
clear_directory
(
directory
);
directory_delete
(
directory
);
}
bool
delete_name_in
(
struct
directory
*
parent
,
const
char
*
name
)
{
bool
modified
=
false
;
db_lock
();
struct
directory
*
directory
=
directory_get_child
(
parent
,
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
;
}
db_unlock
();
playlist_vector_remove
(
&
parent
->
playlists
,
name
);
return
modified
;
}
src/update_db.h
0 → 100644
View file @
4fdcc049
/*
* Copyright (C) 2003-2012 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_UPDATE_DB_H
#define MPD_UPDATE_DB_H
#include "check.h"
#include <stdbool.h>
struct
directory
;
struct
song
;
/**
* Caller must lock the #db_mutex.
*/
void
delete_song
(
struct
directory
*
parent
,
struct
song
*
song
);
/**
* Recursively free a directory and all its contents.
*
* Caller must lock the #db_mutex.
*/
void
delete_directory
(
struct
directory
*
directory
);
/**
* Caller must NOT lock the #db_mutex.
*
* @return true if the database was modified
*/
bool
delete_name_in
(
struct
directory
*
parent
,
const
char
*
name
);
#endif
src/update_walk.c
View file @
4fdcc049
...
...
@@ -20,6 +20,7 @@
#include "config.h"
/* must be first for large file support */
#include "update_internal.h"
#include "update_io.h"
#include "update_db.h"
#include "database.h"
#include "db_lock.h"
#include "exclude.h"
...
...
@@ -93,88 +94,6 @@ directory_set_stat(struct directory *dir, const struct stat *st)
dir
->
have_stat
=
true
;
}
/**
* Caller must lock the #db_mutex.
*/
static
void
delete_song
(
struct
directory
*
dir
,
struct
song
*
del
)
{
assert
(
del
->
parent
==
dir
);
/* first, prevent traversers in main task from getting this */
directory_remove_song
(
dir
,
del
);
db_unlock
();
/* temporary unlock, because update_remove_song() blocks */
/* now take it out of the playlist (in the main_task) */
update_remove_song
(
del
);
/* finally, all possible references gone, free it */
song_free
(
del
);
db_lock
();
}
static
void
delete_directory
(
struct
directory
*
directory
);
/**
* Recursively remove all sub directories and songs from a directory,
* leaving an empty directory.
*
* Caller must lock the #db_mutex.
*/
static
void
clear_directory
(
struct
directory
*
directory
)
{
struct
directory
*
child
,
*
n
;
directory_for_each_child_safe
(
child
,
n
,
directory
)
delete_directory
(
child
);
struct
song
*
song
,
*
ns
;
directory_for_each_song_safe
(
song
,
ns
,
directory
)
{
assert
(
song
->
parent
==
directory
);
delete_song
(
directory
,
song
);
}
}
/**
* Recursively free a directory and all its contents.
*
* Caller must lock the #db_mutex.
*/
static
void
delete_directory
(
struct
directory
*
directory
)
{
assert
(
directory
->
parent
!=
NULL
);
clear_directory
(
directory
);
directory_delete
(
directory
);
}
static
void
delete_name_in
(
struct
directory
*
parent
,
const
char
*
name
)
{
db_lock
();
struct
directory
*
directory
=
directory_get_child
(
parent
,
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
;
}
db_unlock
();
playlist_vector_remove
(
&
parent
->
playlists
,
name
);
}
static
void
remove_excluded_from_directory
(
struct
directory
*
directory
,
GSList
*
exclude_list
)
...
...
@@ -717,7 +636,7 @@ updateDirectory(struct directory *directory, const struct stat *st)
continue
;
if
(
skip_symlink
(
directory
,
utf8
))
{
delete_name_in
(
directory
,
utf8
);
modified
|=
delete_name_in
(
directory
,
utf8
);
g_free
(
utf8
);
continue
;
}
...
...
@@ -725,7 +644,7 @@ updateDirectory(struct directory *directory, const struct stat *st)
if
(
stat_directory_child
(
directory
,
utf8
,
&
st2
)
==
0
)
updateInDirectory
(
directory
,
utf8
,
&
st2
);
else
delete_name_in
(
directory
,
utf8
);
modified
|=
delete_name_in
(
directory
,
utf8
);
g_free
(
utf8
);
}
...
...
@@ -810,7 +729,7 @@ updatePath(const char *path)
if
(
stat_directory_child
(
parent
,
name
,
&
st
)
==
0
)
updateInDirectory
(
parent
,
name
,
&
st
);
else
delete_name_in
(
parent
,
name
);
modified
|=
delete_name_in
(
parent
,
name
);
g_free
(
name
);
}
...
...
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