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
93f0bb83
Commit
93f0bb83
authored
Jan 03, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ExcludeList: convert to a class
parent
47fc08bf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
47 deletions
+61
-47
ExcludeList.cxx
src/ExcludeList.cxx
+8
-22
ExcludeList.hxx
src/ExcludeList.hxx
+45
-16
UpdateWalk.cxx
src/UpdateWalk.cxx
+8
-9
No files found.
src/ExcludeList.cxx
View file @
93f0bb83
...
...
@@ -34,8 +34,8 @@ extern "C" {
#include <stdio.h>
#include <errno.h>
GSList
*
exclude_list_load
(
const
char
*
path_fs
)
bool
ExcludeList
::
LoadFile
(
const
char
*
path_fs
)
{
assert
(
path_fs
!=
NULL
);
...
...
@@ -48,10 +48,9 @@ exclude_list_load(const char *path_fs)
g_free
(
path_utf8
);
}
return
NULL
;
return
false
;
}
GSList
*
list
=
NULL
;
char
line
[
1024
];
while
(
fgets
(
line
,
sizeof
(
line
),
file
)
!=
NULL
)
{
char
*
p
=
strchr
(
line
,
'#'
);
...
...
@@ -60,37 +59,24 @@ exclude_list_load(const char *path_fs)
p
=
g_strstrip
(
line
);
if
(
*
p
!=
0
)
list
=
g_slist_prepend
(
list
,
g_pattern_spec_new
(
p
)
);
patterns
.
emplace_front
(
p
);
}
fclose
(
file
);
return
list
;
}
void
exclude_list_free
(
GSList
*
list
)
{
while
(
list
!=
NULL
)
{
GPatternSpec
*
pattern
=
(
GPatternSpec
*
)
list
->
data
;
g_pattern_spec_free
(
pattern
);
list
=
g_slist_remove
(
list
,
list
->
data
);
}
return
true
;
}
bool
exclude_list_check
(
GSList
*
list
,
const
char
*
name_fs
)
ExcludeList
::
Check
(
const
char
*
name_fs
)
const
{
assert
(
name_fs
!=
NULL
);
/* XXX include full path name in check */
for
(;
list
!=
NULL
;
list
=
list
->
next
)
{
GPatternSpec
*
pattern
=
(
GPatternSpec
*
)
list
->
data
;
if
(
g_pattern_match_string
(
pattern
,
name_fs
))
for
(
const
auto
&
i
:
patterns
)
if
(
i
.
Check
(
name_fs
))
return
true
;
}
return
false
;
}
src/ExcludeList.hxx
View file @
93f0bb83
...
...
@@ -25,25 +25,54 @@
#ifndef MPD_EXCLUDE_H
#define MPD_EXCLUDE_H
#include "gcc.h"
#include <forward_list>
#include <glib.h>
/**
* Loads and parses a .mpdignore file.
*/
GSList
*
exclude_list_load
(
const
char
*
path_fs
);
class
ExcludeList
{
class
Pattern
{
GPatternSpec
*
pattern
;
/**
* Frees a list returned by exclude_list_load().
*/
void
exclude_list_free
(
GSList
*
list
);
public
:
Pattern
(
const
char
*
_pattern
)
:
pattern
(
g_pattern_spec_new
(
_pattern
))
{}
Pattern
(
Pattern
&&
other
)
:
pattern
(
other
.
pattern
)
{
other
.
pattern
=
nullptr
;
}
~
Pattern
()
{
g_pattern_spec_free
(
pattern
);
}
gcc_pure
bool
Check
(
const
char
*
name_fs
)
const
{
return
g_pattern_match_string
(
pattern
,
name_fs
);
}
};
std
::
forward_list
<
Pattern
>
patterns
;
public
:
gcc_pure
bool
IsEmpty
()
const
{
return
patterns
.
empty
();
}
/**
* Loads and parses a .mpdignore file.
*/
bool
LoadFile
(
const
char
*
path_fs
);
/**
* Checks whether one of the patterns in the .mpdignore file matches
* the specified file name.
*/
bool
Check
(
const
char
*
name_fs
)
const
;
};
/**
* Checks whether one of the patterns in the .mpdignore file matches
* the specified file name.
*/
bool
exclude_list_check
(
GSList
*
list
,
const
char
*
name_fs
);
#endif
src/UpdateWalk.cxx
View file @
93f0bb83
...
...
@@ -95,7 +95,8 @@ directory_set_stat(Directory *dir, const struct stat *st)
}
static
void
remove_excluded_from_directory
(
Directory
*
directory
,
GSList
*
exclude_list
)
remove_excluded_from_directory
(
Directory
*
directory
,
const
ExcludeList
&
exclude_list
)
{
db_lock
();
...
...
@@ -103,7 +104,7 @@ remove_excluded_from_directory(Directory *directory, GSList *exclude_list)
directory_for_each_child_safe
(
child
,
n
,
directory
)
{
char
*
name_fs
=
utf8_to_fs_charset
(
child
->
GetName
());
if
(
exclude_list
_check
(
exclude_list
,
name_fs
))
{
if
(
exclude_list
.
Check
(
name_fs
))
{
delete_directory
(
child
);
modified
=
true
;
}
...
...
@@ -116,7 +117,7 @@ remove_excluded_from_directory(Directory *directory, GSList *exclude_list)
assert
(
song
->
parent
==
directory
);
char
*
name_fs
=
utf8_to_fs_charset
(
song
->
uri
);
if
(
exclude_list
_check
(
exclude_list
,
name_fs
))
{
if
(
exclude_list
.
Check
(
name_fs
))
{
delete_song
(
directory
,
song
);
modified
=
true
;
}
...
...
@@ -371,12 +372,13 @@ update_directory(Directory *directory, const struct stat *st)
}
char
*
exclude_path_fs
=
g_build_filename
(
path_fs
,
".mpdignore"
,
NULL
);
GSList
*
exclude_list
=
exclude_list_load
(
exclude_path_fs
);
ExcludeList
exclude_list
;
exclude_list
.
LoadFile
(
exclude_path_fs
);
g_free
(
exclude_path_fs
);
g_free
(
path_fs
);
if
(
exclude_list
!=
NULL
)
if
(
!
exclude_list
.
IsEmpty
()
)
remove_excluded_from_directory
(
directory
,
exclude_list
);
purge_deleted_from_directory
(
directory
);
...
...
@@ -386,8 +388,7 @@ update_directory(Directory *directory, const struct stat *st)
char
*
utf8
;
struct
stat
st2
;
if
(
skip_path
(
ent
->
d_name
)
||
exclude_list_check
(
exclude_list
,
ent
->
d_name
))
if
(
skip_path
(
ent
->
d_name
)
||
exclude_list
.
Check
(
ent
->
d_name
))
continue
;
utf8
=
fs_charset_to_utf8
(
ent
->
d_name
);
...
...
@@ -408,8 +409,6 @@ update_directory(Directory *directory, const struct stat *st)
g_free
(
utf8
);
}
exclude_list_free
(
exclude_list
);
closedir
(
dir
);
directory
->
mtime
=
st
->
st_mtime
;
...
...
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