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
1d9b84a5
Commit
1d9b84a5
authored
May 05, 2013
by
Denis Krjuchkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PlaylistFile: use DirectoryReader and file system API
parent
a688745b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
27 deletions
+24
-27
PlaylistFile.cxx
src/PlaylistFile.cxx
+24
-27
No files found.
src/PlaylistFile.cxx
View file @
1d9b84a5
...
...
@@ -32,6 +32,7 @@
#include "Idle.hxx"
#include "fs/Path.hxx"
#include "fs/FileSystem.hxx"
#include "fs/DirectoryReader.hxx"
#include "util/UriUtil.hxx"
#include <assert.h>
...
...
@@ -77,7 +78,7 @@ spl_valid_name(const char *name_utf8)
strchr
(
name_utf8
,
'\r'
)
==
NULL
;
}
static
const
char
*
static
const
Path
&
spl_map
(
GError
**
error_r
)
{
const
Path
&
path_fs
=
map_spl_path
();
...
...
@@ -85,8 +86,7 @@ spl_map(GError **error_r)
g_set_error_literal
(
error_r
,
playlist_quark
(),
PLAYLIST_RESULT_DISABLED
,
"Stored playlists are disabled"
);
return
path_fs
.
c_str
();
return
path_fs
;
}
static
bool
...
...
@@ -105,8 +105,7 @@ spl_check_name(const char *name_utf8, GError **error_r)
static
Path
spl_map_to_fs
(
const
char
*
name_utf8
,
GError
**
error_r
)
{
if
(
spl_map
(
error_r
)
==
NULL
||
!
spl_check_name
(
name_utf8
,
error_r
))
if
(
spl_map
(
error_r
).
IsNull
()
||
!
spl_check_name
(
name_utf8
,
error_r
))
return
Path
::
Null
();
Path
path_fs
=
map_spl_utf8_to_fs
(
name_utf8
);
...
...
@@ -139,25 +138,24 @@ playlist_errno(GError **error_r)
static
bool
LoadPlaylistFileInfo
(
PlaylistInfo
&
info
,
const
char
*
parent_path_fs
,
const
char
*
name_fs
)
const
Path
&
parent_path_fs
,
const
Path
&
name_fs
)
{
size_t
name_length
=
strlen
(
name_fs
);
const
char
*
name_fs_str
=
name_fs
.
c_str
();
size_t
name_length
=
strlen
(
name_fs_str
);
if
(
name_length
<
sizeof
(
PLAYLIST_FILE_SUFFIX
)
||
memchr
(
name_fs
,
'\n'
,
name_length
)
!=
NULL
)
memchr
(
name_fs
_str
,
'\n'
,
name_length
)
!=
NULL
)
return
false
;
if
(
!
g_str_has_suffix
(
name_fs
,
PLAYLIST_FILE_SUFFIX
))
if
(
!
g_str_has_suffix
(
name_fs
_str
,
PLAYLIST_FILE_SUFFIX
))
return
false
;
char
*
path_fs
=
g_build_filename
(
parent_path_fs
,
name_fs
,
NULL
);
Path
path_fs
=
Path
::
Build
(
parent_path_fs
,
name_fs
);
struct
stat
st
;
int
ret
=
stat
(
path_fs
,
&
st
);
g_free
(
path_fs
);
if
(
ret
<
0
||
!
S_ISREG
(
st
.
st_mode
))
if
(
!
StatFile
(
path_fs
,
st
)
||
!
S_ISREG
(
st
.
st_mode
))
return
false
;
char
*
name
=
g_strndup
(
name_fs
,
char
*
name
=
g_strndup
(
name_fs
_str
,
name_length
+
1
-
sizeof
(
PLAYLIST_FILE_SUFFIX
));
std
::
string
name_utf8
=
Path
::
ToUTF8
(
name
);
g_free
(
name
);
...
...
@@ -174,24 +172,23 @@ ListPlaylistFiles(GError **error_r)
{
PlaylistVector
list
;
const
char
*
parent_path_fs
=
spl_map
(
error_r
);
if
(
parent_path_fs
==
NULL
)
const
Path
&
parent_path_fs
=
spl_map
(
error_r
);
if
(
parent_path_fs
.
IsNull
()
)
return
list
;
D
IR
*
dir
=
opendi
r
(
parent_path_fs
);
if
(
dir
==
NULL
)
{
D
irectoryReader
reade
r
(
parent_path_fs
);
if
(
reader
.
HasFailed
()
)
{
set_error_errno
(
error_r
);
return
list
;
}
PlaylistInfo
info
;
struct
dirent
*
ent
;
while
((
ent
=
readdir
(
dir
))
!=
NULL
)
{
if
(
LoadPlaylistFileInfo
(
info
,
parent_path_fs
,
ent
->
d_name
))
while
(
reader
.
ReadEntry
())
{
const
Path
entry
=
reader
.
GetEntry
();
if
(
LoadPlaylistFileInfo
(
info
,
parent_path_fs
,
ent
ry
))
list
.
push_back
(
std
::
move
(
info
));
}
closedir
(
dir
);
return
list
;
}
...
...
@@ -201,7 +198,7 @@ SavePlaylistFile(const PlaylistFileContents &contents, const char *utf8path,
{
assert
(
utf8path
!=
NULL
);
if
(
spl_map
(
error_r
)
==
NULL
)
if
(
spl_map
(
error_r
)
.
IsNull
()
)
return
false
;
const
Path
path_fs
=
spl_map_to_fs
(
utf8path
,
error_r
);
...
...
@@ -226,7 +223,7 @@ LoadPlaylistFile(const char *utf8path, GError **error_r)
{
PlaylistFileContents
contents
;
if
(
spl_map
(
error_r
)
==
NULL
)
if
(
spl_map
(
error_r
)
.
IsNull
()
)
return
contents
;
const
Path
path_fs
=
spl_map_to_fs
(
utf8path
,
error_r
);
...
...
@@ -302,7 +299,7 @@ spl_move_index(const char *utf8path, unsigned src, unsigned dest,
bool
spl_clear
(
const
char
*
utf8path
,
GError
**
error_r
)
{
if
(
spl_map
(
error_r
)
==
NULL
)
if
(
spl_map
(
error_r
)
.
IsNull
()
)
return
false
;
const
Path
path_fs
=
spl_map_to_fs
(
utf8path
,
error_r
);
...
...
@@ -365,7 +362,7 @@ spl_remove_index(const char *utf8path, unsigned pos, GError **error_r)
bool
spl_append_song
(
const
char
*
utf8path
,
struct
song
*
song
,
GError
**
error_r
)
{
if
(
spl_map
(
error_r
)
==
NULL
)
if
(
spl_map
(
error_r
)
.
IsNull
()
)
return
false
;
const
Path
path_fs
=
spl_map_to_fs
(
utf8path
,
error_r
);
...
...
@@ -454,7 +451,7 @@ spl_rename_internal(const Path &from_path_fs, const Path &to_path_fs,
bool
spl_rename
(
const
char
*
utf8from
,
const
char
*
utf8to
,
GError
**
error_r
)
{
if
(
spl_map
(
error_r
)
==
NULL
)
if
(
spl_map
(
error_r
)
.
IsNull
()
)
return
false
;
Path
from_path_fs
=
spl_map_to_fs
(
utf8from
,
error_r
);
...
...
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