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
72255d58
Commit
72255d58
authored
Jan 02, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mapper: allocate the result of map_uri_fs(), map_directory_fs()
Don't use fixed stack buffers.
parent
b2e3b644
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
37 deletions
+40
-37
mapper.c
src/mapper.c
+10
-19
mapper.h
src/mapper.h
+4
-4
playlist_save.c
src/playlist_save.c
+8
-4
update.c
src/update.c
+18
-10
No files found.
src/mapper.c
View file @
72255d58
...
...
@@ -89,53 +89,44 @@ void mapper_finish(void)
g_free
(
playlist_dir
);
}
static
char
*
rmp2amp_r
(
char
*
dst
,
const
char
*
rel_path
)
{
pfx_dir
(
dst
,
rel_path
,
strlen
(
rel_path
),
(
const
char
*
)
music_dir
,
music_dir_length
);
return
dst
;
}
const
char
*
map_uri_fs
(
const
char
*
uri
,
char
*
buffer
)
char
*
map_uri_fs
(
const
char
*
uri
)
{
assert
(
uri
!=
NULL
);
assert
(
*
uri
!=
'/'
);
assert
(
buffer
!=
NULL
);
return
rmp2amp_r
(
buffer
,
utf8_to_fs_charset
(
buffer
,
uri
)
);
return
g_build_filename
(
music_dir
,
uri
,
NULL
);
}
c
onst
c
har
*
map_directory_fs
(
const
struct
directory
*
directory
,
char
*
buffer
)
char
*
map_directory_fs
(
const
struct
directory
*
directory
)
{
const
char
*
dirname
=
directory_get_path
(
directory
);
if
(
isRootDirectory
(
dirname
))
return
music_dir
;
return
g_strdup
(
music_dir
)
;
return
map_uri_fs
(
dirname
,
buffer
);
return
map_uri_fs
(
dirname
);
}
const
char
*
map_directory_child_fs
(
const
struct
directory
*
directory
,
const
char
*
name
,
char
*
buffer
)
{
char
buffer2
[
MPD_PATH_MAX
];
const
char
*
parent_fs
;
char
*
parent_fs
;
/* check for invalid or unauthorized base names */
if
(
*
name
==
0
||
strchr
(
name
,
'/'
)
!=
NULL
||
strcmp
(
name
,
"."
)
==
0
||
strcmp
(
name
,
".."
)
==
0
)
return
NULL
;
parent_fs
=
map_directory_fs
(
directory
,
buffer2
);
parent_fs
=
map_directory_fs
(
directory
);
if
(
parent_fs
==
NULL
)
return
NULL
;
name
=
utf8_to_fs_charset
(
buffer
,
name
);
pfx_dir
(
buffer
,
name
,
strlen
(
name
),
parent_fs
,
strlen
(
parent_fs
));
g_free
(
parent_fs
);
return
buffer
;
}
...
...
src/mapper.h
View file @
72255d58
...
...
@@ -37,8 +37,8 @@ void mapper_finish(void);
* is basically done by converting the URI to the file system charset
* and prepending the music directory.
*/
c
onst
c
har
*
map_uri_fs
(
const
char
*
uri
,
char
*
buffer
);
char
*
map_uri_fs
(
const
char
*
uri
);
/**
* Determines the file system path of a directory object.
...
...
@@ -47,8 +47,8 @@ map_uri_fs(const char *uri, char *buffer);
* @param a buffer which is MPD_PATH_MAX bytes long
* @return the path in file system encoding, or NULL if mapping failed
*/
c
onst
c
har
*
map_directory_fs
(
const
struct
directory
*
directory
,
char
*
buffer
);
char
*
map_directory_fs
(
const
struct
directory
*
directory
);
/**
* Determines the file system path of a directory's child (may be a
...
...
src/playlist_save.c
View file @
72255d58
...
...
@@ -24,6 +24,8 @@
#include "ls.h"
#include "database.h"
#include <glib.h>
void
playlist_print_song
(
FILE
*
file
,
const
struct
song
*
song
)
{
...
...
@@ -44,14 +46,16 @@ void
playlist_print_uri
(
FILE
*
file
,
const
char
*
uri
)
{
char
tmp
[
MPD_PATH_MAX
];
c
onst
c
har
*
s
;
char
*
s
;
if
(
playlist_saveAbsolutePaths
&&
!
isRemoteUrl
(
uri
)
&&
uri
[
0
]
!=
'/'
)
s
=
map_uri_fs
(
uri
,
tmp
);
s
=
map_uri_fs
(
uri
);
else
s
=
utf8_to_fs_charset
(
tmp
,
uri
);
s
=
g_strdup
(
utf8_to_fs_charset
(
tmp
,
uri
)
);
if
(
s
!=
NULL
)
if
(
s
!=
NULL
)
{
fprintf
(
file
,
"%s
\n
"
,
s
);
g_free
(
s
);
}
}
src/update.c
View file @
72255d58
...
...
@@ -191,11 +191,16 @@ removeDeletedFromDirectory(char *path_max_tmp, struct directory *directory)
struct
delete_data
data
;
for
(
i
=
dv
->
nr
;
--
i
>=
0
;
)
{
const
char
*
path_fs
;
char
*
path_fs
;
bool
is_dir
;
path_fs
=
map_directory_fs
(
dv
->
base
[
i
],
path_max_tmp
);
if
(
path_fs
==
NULL
||
!
g_file_test
(
path_fs
,
G_FILE_TEST_IS_DIR
))
path_fs
=
map_directory_fs
(
dv
->
base
[
i
]);
if
(
path_fs
==
NULL
)
continue
;
is_dir
=
g_file_test
(
path_fs
,
G_FILE_TEST_IS_DIR
);
g_free
(
path_fs
);
if
(
!
is_dir
)
continue
;
g_debug
(
"removing directory: %s"
,
dv
->
base
[
i
]
->
path
);
dirvec_delete
(
dv
,
dv
->
base
[
i
]);
...
...
@@ -210,13 +215,15 @@ removeDeletedFromDirectory(char *path_max_tmp, struct directory *directory)
static
int
stat_directory
(
const
struct
directory
*
directory
,
struct
stat
*
st
)
{
char
buffer
[
MPD_PATH_MAX
]
;
const
char
*
path_fs
;
char
*
path_fs
;
int
ret
;
path_fs
=
map_directory_fs
(
directory
,
buffer
);
path_fs
=
map_directory_fs
(
directory
);
if
(
path_fs
==
NULL
)
return
-
1
;
return
stat
(
path_fs
,
st
);
ret
=
stat
(
path_fs
,
st
);
g_free
(
path_fs
);
return
ret
;
}
static
int
...
...
@@ -471,17 +478,18 @@ updateDirectory(struct directory *directory, const struct stat *st)
DIR
*
dir
;
struct
dirent
*
ent
;
char
path_max_tmp
[
MPD_PATH_MAX
];
c
onst
c
har
*
path_fs
;
char
*
path_fs
;
assert
(
S_ISDIR
(
st
->
st_mode
));
directory_set_stat
(
directory
,
st
);
path_fs
=
map_directory_fs
(
directory
,
path_max_tmp
);
path_fs
=
map_directory_fs
(
directory
);
if
(
path_fs
==
NULL
)
return
false
;
dir
=
opendir
(
path_fs
);
g_free
(
path_fs
);
if
(
!
dir
)
return
false
;
...
...
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