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
d8e877e3
Commit
d8e877e3
authored
Oct 31, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
path: moved playlist_dir to mapper.c
Added the function map_spl_utf8_to_fs() which replaces utf8_to_fs_playlist_path().
parent
ef542716
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
81 additions
and
58 deletions
+81
-58
mapper.c
src/mapper.c
+38
-0
mapper.h
src/mapper.h
+15
-0
path.c
src/path.c
+0
-28
path.h
src/path.h
+0
-9
playlist.c
src/playlist.c
+4
-3
playlist.h
src/playlist.h
+0
-1
stored_playlist.c
src/stored_playlist.c
+24
-17
No files found.
src/mapper.c
View file @
d8e877e3
...
@@ -34,9 +34,13 @@
...
@@ -34,9 +34,13 @@
static
char
*
music_dir
;
static
char
*
music_dir
;
static
size_t
music_dir_length
;
static
size_t
music_dir_length
;
static
char
*
playlist_dir
;
static
size_t
playlist_dir_length
;
void
mapper_init
(
void
)
void
mapper_init
(
void
)
{
{
ConfigParam
*
music_dir_param
=
parseConfigFilePath
(
CONF_MUSIC_DIR
,
1
);
ConfigParam
*
music_dir_param
=
parseConfigFilePath
(
CONF_MUSIC_DIR
,
1
);
ConfigParam
*
playlist_dir_param
=
parseConfigFilePath
(
CONF_PLAYLIST_DIR
,
1
);
int
ret
;
int
ret
;
struct
stat
st
;
struct
stat
st
;
...
@@ -51,11 +55,24 @@ void mapper_init(void)
...
@@ -51,11 +55,24 @@ void mapper_init(void)
else
if
(
!
S_ISDIR
(
st
.
st_mode
))
else
if
(
!
S_ISDIR
(
st
.
st_mode
))
g_warning
(
"music directory is not a directory:
\"
%s
\"
(config line %i)
\n
"
,
g_warning
(
"music directory is not a directory:
\"
%s
\"
(config line %i)
\n
"
,
music_dir_param
->
value
,
music_dir_param
->
line
);
music_dir_param
->
value
,
music_dir_param
->
line
);
playlist_dir
=
g_strdup
(
playlist_dir_param
->
value
);
playlist_dir_length
=
strlen
(
playlist_dir
);
ret
=
stat
(
playlist_dir
,
&
st
);
if
(
ret
<
0
)
g_warning
(
"failed to stat playlist directory
\"
%s
\"
(config line %i): %s
\n
"
,
playlist_dir_param
->
value
,
playlist_dir_param
->
line
,
strerror
(
errno
));
else
if
(
!
S_ISDIR
(
st
.
st_mode
))
g_warning
(
"playlist directory is not a directory:
\"
%s
\"
(config line %i)
\n
"
,
playlist_dir_param
->
value
,
playlist_dir_param
->
line
);
}
}
void
mapper_finish
(
void
)
void
mapper_finish
(
void
)
{
{
g_free
(
music_dir
);
g_free
(
music_dir
);
g_free
(
playlist_dir
);
}
}
static
char
*
static
char
*
...
@@ -117,3 +134,24 @@ map_fs_to_utf8(const char *path_fs, char *buffer)
...
@@ -117,3 +134,24 @@ map_fs_to_utf8(const char *path_fs, char *buffer)
return
fs_charset_to_utf8
(
buffer
,
path_fs
);
return
fs_charset_to_utf8
(
buffer
,
path_fs
);
}
}
static
char
*
rpp2app_r
(
char
*
dst
,
const
char
*
rel_path
)
{
pfx_dir
(
dst
,
rel_path
,
strlen
(
rel_path
),
playlist_dir
,
playlist_dir_length
);
return
dst
;
}
const
char
*
map_spl_path
(
void
)
{
return
playlist_dir
;
}
const
char
*
map_spl_utf8_to_fs
(
const
char
*
name
,
char
*
buffer
)
{
rpp2app_r
(
buffer
,
utf8_to_fs_charset
(
buffer
,
name
));
g_strlcat
(
buffer
,
"."
PLAYLIST_FILE_SUFFIX
,
MPD_PATH_MAX
);
return
buffer
;
}
src/mapper.h
View file @
d8e877e3
...
@@ -23,6 +23,8 @@
...
@@ -23,6 +23,8 @@
#ifndef MPD_MAPPER_H
#ifndef MPD_MAPPER_H
#define MPD_MAPPER_H
#define MPD_MAPPER_H
#define PLAYLIST_FILE_SUFFIX "m3u"
struct
directory
;
struct
directory
;
struct
song
;
struct
song
;
...
@@ -75,4 +77,17 @@ map_song_fs(const struct song *song, char *buffer);
...
@@ -75,4 +77,17 @@ map_song_fs(const struct song *song, char *buffer);
const
char
*
const
char
*
map_fs_to_utf8
(
const
char
*
path_fs
,
char
*
buffer
);
map_fs_to_utf8
(
const
char
*
path_fs
,
char
*
buffer
);
/**
* Returns the playlist directory.
*/
const
char
*
map_spl_path
(
void
);
/**
* Maps a playlist name (without the ".m3u" suffix) to a file system
* path.
*/
const
char
*
map_spl_utf8_to_fs
(
const
char
*
name
,
char
*
buffer
);
#endif
#endif
src/path.c
View file @
d8e877e3
...
@@ -32,8 +32,6 @@
...
@@ -32,8 +32,6 @@
#include <glib.h>
#include <glib.h>
static
const
char
*
playlistDir
;
static
size_t
playlist_dir_len
;
static
char
*
fsCharset
;
static
char
*
fsCharset
;
char
*
fs_charset_to_utf8
(
char
*
dst
,
const
char
*
str
)
char
*
fs_charset_to_utf8
(
char
*
dst
,
const
char
*
str
)
...
@@ -99,22 +97,10 @@ const char *getFsCharset(void)
...
@@ -99,22 +97,10 @@ const char *getFsCharset(void)
void
initPaths
(
void
)
void
initPaths
(
void
)
{
{
ConfigParam
*
playlistParam
=
parseConfigFilePath
(
CONF_PLAYLIST_DIR
,
1
);
ConfigParam
*
fsCharsetParam
=
getConfigParam
(
CONF_FS_CHARSET
);
ConfigParam
*
fsCharsetParam
=
getConfigParam
(
CONF_FS_CHARSET
);
char
*
charset
=
NULL
;
char
*
charset
=
NULL
;
char
*
originalLocale
;
char
*
originalLocale
;
DIR
*
dir
;
playlistDir
=
xstrdup
(
playlistParam
->
value
);
playlist_dir_len
=
strlen
(
playlistDir
);
if
((
dir
=
opendir
(
playlistDir
))
==
NULL
)
{
ERROR
(
"cannot open %s
\"
%s
\"
(config line %i): %s
\n
"
,
CONF_PLAYLIST_DIR
,
playlistParam
->
value
,
playlistParam
->
line
,
strerror
(
errno
));
}
else
closedir
(
dir
);
if
(
fsCharsetParam
)
{
if
(
fsCharsetParam
)
{
charset
=
xstrdup
(
fsCharsetParam
->
value
);
charset
=
xstrdup
(
fsCharsetParam
->
value
);
...
@@ -183,13 +169,6 @@ char *pfx_dir(char *dst,
...
@@ -183,13 +169,6 @@ char *pfx_dir(char *dst,
return
(
dst
+
pfx_len
+
1
);
return
(
dst
+
pfx_len
+
1
);
}
}
char
*
rpp2app_r
(
char
*
dst
,
const
char
*
rel_path
)
{
pfx_dir
(
dst
,
rel_path
,
strlen
(
rel_path
),
(
const
char
*
)
playlistDir
,
playlist_dir_len
);
return
dst
;
}
char
*
sanitizePathDup
(
const
char
*
path
)
char
*
sanitizePathDup
(
const
char
*
path
)
{
{
int
len
=
strlen
(
path
)
+
1
;
int
len
=
strlen
(
path
)
+
1
;
...
@@ -229,10 +208,3 @@ char *sanitizePathDup(const char *path)
...
@@ -229,10 +208,3 @@ char *sanitizePathDup(const char *path)
return
xrealloc
(
ret
,
len
+
1
);
return
xrealloc
(
ret
,
len
+
1
);
}
}
void
utf8_to_fs_playlist_path
(
char
*
path_max_tmp
,
const
char
*
utf8path
)
{
utf8_to_fs_charset
(
path_max_tmp
,
utf8path
);
rpp2app_r
(
path_max_tmp
,
path_max_tmp
);
strncat
(
path_max_tmp
,
"."
PLAYLIST_FILE_SUFFIX
,
MPD_PATH_MAX
-
1
);
}
src/path.h
View file @
d8e877e3
...
@@ -55,16 +55,7 @@ char *pfx_dir(char *dst,
...
@@ -55,16 +55,7 @@ char *pfx_dir(char *dst,
const
char
*
path
,
const
size_t
path_len
,
const
char
*
path
,
const
size_t
path_len
,
const
char
*
pfx
,
const
size_t
pfx_len
);
const
char
*
pfx
,
const
size_t
pfx_len
);
/* relative playlist path to absolute playlist path */
char
*
rpp2app_r
(
char
*
dst
,
const
char
*
rel_path
);
/* strips extra "///" and leading "/" and trailing "/" */
/* strips extra "///" and leading "/" and trailing "/" */
char
*
sanitizePathDup
(
const
char
*
path
);
char
*
sanitizePathDup
(
const
char
*
path
);
/*
* converts a path passed from a client into an absolute FS path.
* paths passed by clients do NOT have file suffixes in them
*/
void
utf8_to_fs_playlist_path
(
char
*
path_max_tmp
,
const
char
*
utf8path
);
#endif
#endif
src/playlist.c
View file @
d8e877e3
...
@@ -1190,15 +1190,16 @@ enum playlist_result savePlaylist(const char *utf8file)
...
@@ -1190,15 +1190,16 @@ enum playlist_result savePlaylist(const char *utf8file)
FILE
*
fp
;
FILE
*
fp
;
struct
stat
sb
;
struct
stat
sb
;
char
path_max_tmp
[
MPD_PATH_MAX
];
char
path_max_tmp
[
MPD_PATH_MAX
];
const
char
*
path
;
if
(
!
is_valid_playlist_name
(
utf8file
))
if
(
!
is_valid_playlist_name
(
utf8file
))
return
PLAYLIST_RESULT_BAD_NAME
;
return
PLAYLIST_RESULT_BAD_NAME
;
utf8_to_fs_playlist_path
(
path_max_tmp
,
utf8file
);
path
=
map_spl_utf8_to_fs
(
utf8file
,
path_max_tmp
);
if
(
!
stat
(
path
_max_tmp
,
&
sb
))
if
(
!
stat
(
path
,
&
sb
))
return
PLAYLIST_RESULT_LIST_EXISTS
;
return
PLAYLIST_RESULT_LIST_EXISTS
;
while
(
!
(
fp
=
fopen
(
path
_max_tmp
,
"w"
))
&&
errno
==
EINTR
);
while
(
!
(
fp
=
fopen
(
path
,
"w"
))
&&
errno
==
EINTR
);
if
(
fp
==
NULL
)
if
(
fp
==
NULL
)
return
PLAYLIST_RESULT_ERRNO
;
return
PLAYLIST_RESULT_ERRNO
;
...
...
src/playlist.h
View file @
d8e877e3
...
@@ -24,7 +24,6 @@
...
@@ -24,7 +24,6 @@
#include <stdbool.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdio.h>
#define PLAYLIST_FILE_SUFFIX "m3u"
#define PLAYLIST_COMMENT '#'
#define PLAYLIST_COMMENT '#'
struct
client
;
struct
client
;
...
...
src/stored_playlist.c
View file @
d8e877e3
...
@@ -70,13 +70,12 @@ load_playlist_info(const char *parent_path_fs, const char *name_fs)
...
@@ -70,13 +70,12 @@ load_playlist_info(const char *parent_path_fs, const char *name_fs)
GPtrArray
*
GPtrArray
*
spl_list
(
void
)
spl_list
(
void
)
{
{
c
har
parent_path_fs
[
MPD_PATH_MAX
]
;
c
onst
char
*
parent_path_fs
=
map_spl_path
()
;
DIR
*
dir
;
DIR
*
dir
;
struct
dirent
*
ent
;
struct
dirent
*
ent
;
GPtrArray
*
list
;
GPtrArray
*
list
;
struct
stored_playlist_info
*
playlist
;
struct
stored_playlist_info
*
playlist
;
rpp2app_r
(
parent_path_fs
,
""
);
dir
=
opendir
(
parent_path_fs
);
dir
=
opendir
(
parent_path_fs
);
if
(
dir
==
NULL
)
if
(
dir
==
NULL
)
return
NULL
;
return
NULL
;
...
@@ -111,12 +110,13 @@ spl_save(GPtrArray *list, const char *utf8path)
...
@@ -111,12 +110,13 @@ spl_save(GPtrArray *list, const char *utf8path)
{
{
FILE
*
file
;
FILE
*
file
;
char
path_max_tmp
[
MPD_PATH_MAX
];
char
path_max_tmp
[
MPD_PATH_MAX
];
const
char
*
path_fs
;
assert
(
utf8path
!=
NULL
);
assert
(
utf8path
!=
NULL
);
utf8_to_fs_playlist_path
(
path_max_tmp
,
utf8path
);
path_fs
=
map_spl_utf8_to_fs
(
utf8path
,
path_max_tmp
);
while
(
!
(
file
=
fopen
(
path_
max_tmp
,
"w"
))
&&
errno
==
EINTR
);
while
(
!
(
file
=
fopen
(
path_
fs
,
"w"
))
&&
errno
==
EINTR
);
if
(
file
==
NULL
)
if
(
file
==
NULL
)
return
PLAYLIST_RESULT_ERRNO
;
return
PLAYLIST_RESULT_ERRNO
;
...
@@ -136,12 +136,14 @@ spl_load(const char *utf8path)
...
@@ -136,12 +136,14 @@ spl_load(const char *utf8path)
GPtrArray
*
list
;
GPtrArray
*
list
;
char
buffer
[
MPD_PATH_MAX
];
char
buffer
[
MPD_PATH_MAX
];
char
path_max_tmp
[
MPD_PATH_MAX
];
char
path_max_tmp
[
MPD_PATH_MAX
];
const
char
*
path_fs
;
if
(
!
is_valid_playlist_name
(
utf8path
))
if
(
!
is_valid_playlist_name
(
utf8path
))
return
NULL
;
return
NULL
;
utf8_to_fs_playlist_path
(
path_max_tmp
,
utf8path
);
path_fs
=
map_spl_utf8_to_fs
(
utf8path
,
path_max_tmp
);
while
(
!
(
file
=
fopen
(
path_max_tmp
,
"r"
))
&&
errno
==
EINTR
);
while
(
!
(
file
=
fopen
(
path_fs
,
"r"
))
&&
errno
==
EINTR
);
if
(
file
==
NULL
)
if
(
file
==
NULL
)
return
NULL
;
return
NULL
;
...
@@ -248,14 +250,15 @@ enum playlist_result
...
@@ -248,14 +250,15 @@ enum playlist_result
spl_clear
(
const
char
*
utf8path
)
spl_clear
(
const
char
*
utf8path
)
{
{
char
filename
[
MPD_PATH_MAX
];
char
filename
[
MPD_PATH_MAX
];
const
char
*
path_fs
;
FILE
*
file
;
FILE
*
file
;
if
(
!
is_valid_playlist_name
(
utf8path
))
if
(
!
is_valid_playlist_name
(
utf8path
))
return
PLAYLIST_RESULT_BAD_NAME
;
return
PLAYLIST_RESULT_BAD_NAME
;
utf8_to_fs_playlist_path
(
filename
,
utf8path
);
path_fs
=
map_spl_utf8_to_fs
(
utf8path
,
filename
);
while
(
!
(
file
=
fopen
(
filename
,
"w"
))
&&
errno
==
EINTR
);
while
(
!
(
file
=
fopen
(
path_fs
,
"w"
))
&&
errno
==
EINTR
);
if
(
file
==
NULL
)
if
(
file
==
NULL
)
return
PLAYLIST_RESULT_ERRNO
;
return
PLAYLIST_RESULT_ERRNO
;
...
@@ -269,10 +272,11 @@ enum playlist_result
...
@@ -269,10 +272,11 @@ enum playlist_result
spl_delete
(
const
char
*
name_utf8
)
spl_delete
(
const
char
*
name_utf8
)
{
{
char
filename
[
MPD_PATH_MAX
];
char
filename
[
MPD_PATH_MAX
];
const
char
*
path_fs
;
utf8_to_fs_playlist_path
(
filename
,
name_utf8
);
path_fs
=
map_spl_utf8_to_fs
(
name_utf8
,
filename
);
if
(
unlink
(
filename
)
<
0
)
if
(
unlink
(
path_fs
)
<
0
)
return
errno
==
ENOENT
return
errno
==
ENOENT
?
PLAYLIST_RESULT_NO_SUCH_LIST
?
PLAYLIST_RESULT_NO_SUCH_LIST
:
PLAYLIST_RESULT_ERRNO
;
:
PLAYLIST_RESULT_ERRNO
;
...
@@ -312,12 +316,14 @@ spl_append_song(const char *utf8path, struct song *song)
...
@@ -312,12 +316,14 @@ spl_append_song(const char *utf8path, struct song *song)
FILE
*
file
;
FILE
*
file
;
struct
stat
st
;
struct
stat
st
;
char
path_max_tmp
[
MPD_PATH_MAX
];
char
path_max_tmp
[
MPD_PATH_MAX
];
const
char
*
path_fs
;
if
(
!
is_valid_playlist_name
(
utf8path
))
if
(
!
is_valid_playlist_name
(
utf8path
))
return
PLAYLIST_RESULT_BAD_NAME
;
return
PLAYLIST_RESULT_BAD_NAME
;
utf8_to_fs_playlist_path
(
path_max_tmp
,
utf8path
);
while
(
!
(
file
=
fopen
(
path_max_tmp
,
"a"
))
&&
errno
==
EINTR
);
path_fs
=
map_spl_utf8_to_fs
(
utf8path
,
path_max_tmp
);
while
(
!
(
file
=
fopen
(
path_fs
,
"a"
))
&&
errno
==
EINTR
);
if
(
file
==
NULL
)
{
if
(
file
==
NULL
)
{
int
save_errno
=
errno
;
int
save_errno
=
errno
;
while
(
fclose
(
file
)
!=
0
&&
errno
==
EINTR
);
while
(
fclose
(
file
)
!=
0
&&
errno
==
EINTR
);
...
@@ -373,21 +379,22 @@ spl_rename(const char *utf8from, const char *utf8to)
...
@@ -373,21 +379,22 @@ spl_rename(const char *utf8from, const char *utf8to)
struct
stat
st
;
struct
stat
st
;
char
from
[
MPD_PATH_MAX
];
char
from
[
MPD_PATH_MAX
];
char
to
[
MPD_PATH_MAX
];
char
to
[
MPD_PATH_MAX
];
const
char
*
from_path_fs
,
*
to_path_fs
;
if
(
!
is_valid_playlist_name
(
utf8from
)
||
if
(
!
is_valid_playlist_name
(
utf8from
)
||
!
is_valid_playlist_name
(
utf8to
))
!
is_valid_playlist_name
(
utf8to
))
return
PLAYLIST_RESULT_BAD_NAME
;
return
PLAYLIST_RESULT_BAD_NAME
;
utf8_to_fs_playlist_path
(
from
,
utf8
from
);
from_path_fs
=
map_spl_utf8_to_fs
(
utf8from
,
from
);
utf8_to_fs_playlist_path
(
to
,
utf8
to
);
to_path_fs
=
map_spl_utf8_to_fs
(
utf8to
,
to
);
if
(
stat
(
from
,
&
st
)
!=
0
)
if
(
stat
(
from
_path_fs
,
&
st
)
!=
0
)
return
PLAYLIST_RESULT_NO_SUCH_LIST
;
return
PLAYLIST_RESULT_NO_SUCH_LIST
;
if
(
stat
(
to
,
&
st
)
==
0
)
if
(
stat
(
to
_path_fs
,
&
st
)
==
0
)
return
PLAYLIST_RESULT_LIST_EXISTS
;
return
PLAYLIST_RESULT_LIST_EXISTS
;
if
(
rename
(
from
,
to
)
<
0
)
if
(
rename
(
from
_path_fs
,
to_path_fs
)
<
0
)
return
PLAYLIST_RESULT_ERRNO
;
return
PLAYLIST_RESULT_ERRNO
;
idle_add
(
IDLE_STORED_PLAYLIST
);
idle_add
(
IDLE_STORED_PLAYLIST
);
...
...
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