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
ba96920a
Commit
ba96920a
authored
Oct 20, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
path: replaced mpd_basename() with g_path_get_basename()
GLib's g_path_get_basename() is much more reliable than mpd_basename(). The latter could be tricked into an assertion failure.
parent
99e82a2e
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
29 deletions
+30
-29
directory.c
src/directory.c
+2
-1
directory_save.c
src/directory_save.c
+4
-1
dirvec.c
src/dirvec.c
+8
-2
path.c
src/path.c
+0
-12
path.h
src/path.h
+0
-8
update.c
src/update.c
+16
-5
No files found.
src/directory.c
View file @
ba96920a
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
#include <assert.h>
#include <assert.h>
#include <string.h>
#include <string.h>
#include <glib.h>
struct
directory
*
struct
directory
*
directory_new
(
const
char
*
path
,
struct
directory
*
parent
)
directory_new
(
const
char
*
path
,
struct
directory
*
parent
)
...
@@ -53,7 +54,7 @@ directory_free(struct directory *directory)
...
@@ -53,7 +54,7 @@ directory_free(struct directory *directory)
const
char
*
const
char
*
directory_get_name
(
const
struct
directory
*
directory
)
directory_get_name
(
const
struct
directory
*
directory
)
{
{
return
mpd
_basename
(
directory
->
path
);
return
g
_basename
(
directory
->
path
);
}
}
void
void
...
...
src/directory_save.c
View file @
ba96920a
...
@@ -24,6 +24,8 @@
...
@@ -24,6 +24,8 @@
#include "utils.h"
#include "utils.h"
#include "song_save.h"
#include "song_save.h"
#include <glib.h>
/* TODO error checking */
/* TODO error checking */
int
int
directory_save
(
FILE
*
fp
,
struct
directory
*
directory
)
directory_save
(
FILE
*
fp
,
struct
directory
*
directory
)
...
@@ -41,9 +43,10 @@ directory_save(FILE *fp, struct directory *directory)
...
@@ -41,9 +43,10 @@ directory_save(FILE *fp, struct directory *directory)
for
(
i
=
0
;
i
<
children
->
nr
;
++
i
)
{
for
(
i
=
0
;
i
<
children
->
nr
;
++
i
)
{
struct
directory
*
cur
=
children
->
base
[
i
];
struct
directory
*
cur
=
children
->
base
[
i
];
c
onst
char
*
base
=
mpd
_basename
(
cur
->
path
);
c
har
*
base
=
g_path_get
_basename
(
cur
->
path
);
retv
=
fprintf
(
fp
,
DIRECTORY_DIR
"%s
\n
"
,
base
);
retv
=
fprintf
(
fp
,
DIRECTORY_DIR
"%s
\n
"
,
base
);
g_free
(
base
);
if
(
retv
<
0
)
if
(
retv
<
0
)
return
-
1
;
return
-
1
;
if
(
directory_save
(
fp
,
cur
)
<
0
)
if
(
directory_save
(
fp
,
cur
)
<
0
)
...
...
src/dirvec.c
View file @
ba96920a
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include "path.h"
#include "path.h"
#include <string.h>
#include <string.h>
#include <glib.h>
static
size_t
dv_size
(
struct
dirvec
*
dv
)
static
size_t
dv_size
(
struct
dirvec
*
dv
)
{
{
...
@@ -25,13 +26,18 @@ void dirvec_sort(struct dirvec *dv)
...
@@ -25,13 +26,18 @@ void dirvec_sort(struct dirvec *dv)
struct
directory
*
dirvec_find
(
const
struct
dirvec
*
dv
,
const
char
*
path
)
struct
directory
*
dirvec_find
(
const
struct
dirvec
*
dv
,
const
char
*
path
)
{
{
char
*
basename
;
int
i
;
int
i
;
path
=
mpd
_basename
(
path
);
basename
=
g_path_get
_basename
(
path
);
for
(
i
=
dv
->
nr
;
--
i
>=
0
;
)
for
(
i
=
dv
->
nr
;
--
i
>=
0
;
)
if
(
!
strcmp
(
directory_get_name
(
dv
->
base
[
i
]),
path
))
if
(
!
strcmp
(
directory_get_name
(
dv
->
base
[
i
]),
basename
))
{
g_free
(
basename
);
return
dv
->
base
[
i
];
return
dv
->
base
[
i
];
}
g_free
(
basename
);
return
NULL
;
return
NULL
;
}
}
...
...
src/path.c
View file @
ba96920a
...
@@ -276,15 +276,3 @@ void utf8_to_fs_playlist_path(char *path_max_tmp, const char *utf8path)
...
@@ -276,15 +276,3 @@ void utf8_to_fs_playlist_path(char *path_max_tmp, const char *utf8path)
rpp2app_r
(
path_max_tmp
,
path_max_tmp
);
rpp2app_r
(
path_max_tmp
,
path_max_tmp
);
strncat
(
path_max_tmp
,
"."
PLAYLIST_FILE_SUFFIX
,
MPD_PATH_MAX
-
1
);
strncat
(
path_max_tmp
,
"."
PLAYLIST_FILE_SUFFIX
,
MPD_PATH_MAX
-
1
);
}
}
/* Only takes sanitized paths w/o trailing slashes */
const
char
*
mpd_basename
(
const
char
*
path
)
{
const
char
*
ret
=
strrchr
(
path
,
'/'
);
if
(
!
ret
)
return
path
;
++
ret
;
assert
(
*
ret
!=
'\0'
);
return
ret
;
}
src/path.h
View file @
ba96920a
...
@@ -83,12 +83,4 @@ void pathcpy_trunc(char *dest, const char *src);
...
@@ -83,12 +83,4 @@ void pathcpy_trunc(char *dest, const char *src);
*/
*/
void
utf8_to_fs_playlist_path
(
char
*
path_max_tmp
,
const
char
*
utf8path
);
void
utf8_to_fs_playlist_path
(
char
*
path_max_tmp
,
const
char
*
utf8path
);
/*
* Like basename(3) but with predictable semantics independent
* of C library or build options used. This is also much more strict
* and does not account for trailing slashes (mpd should never deal with
* trailing slashes on internal functions).
*/
const
char
*
mpd_basename
(
const
char
*
path
);
#endif
#endif
src/update.c
View file @
ba96920a
...
@@ -32,6 +32,8 @@
...
@@ -32,6 +32,8 @@
#include "update.h"
#include "update.h"
#include "idle.h"
#include "idle.h"
#include <glib.h>
static
enum
update_progress
{
static
enum
update_progress
{
UPDATE_PROGRESS_IDLE
=
0
,
UPDATE_PROGRESS_IDLE
=
0
,
UPDATE_PROGRESS_RUNNING
=
1
,
UPDATE_PROGRESS_RUNNING
=
1
,
...
@@ -407,6 +409,7 @@ static struct directory *
...
@@ -407,6 +409,7 @@ static struct directory *
directory_make_child_checked
(
struct
directory
*
parent
,
const
char
*
path
)
directory_make_child_checked
(
struct
directory
*
parent
,
const
char
*
path
)
{
{
struct
directory
*
directory
;
struct
directory
*
directory
;
char
*
basename
;
struct
stat
st
;
struct
stat
st
;
struct
song
*
conflicting
;
struct
song
*
conflicting
;
...
@@ -414,16 +417,22 @@ directory_make_child_checked(struct directory *parent, const char *path)
...
@@ -414,16 +417,22 @@ directory_make_child_checked(struct directory *parent, const char *path)
if
(
directory
!=
NULL
)
if
(
directory
!=
NULL
)
return
directory
;
return
directory
;
if
(
stat_directory_child
(
parent
,
mpd_basename
(
path
),
&
st
)
<
0
||
basename
=
g_path_get_basename
(
path
);
inodeFoundInParent
(
parent
,
st
.
st_ino
,
st
.
st_dev
))
if
(
stat_directory_child
(
parent
,
basename
,
&
st
)
<
0
||
inodeFoundInParent
(
parent
,
st
.
st_ino
,
st
.
st_dev
))
{
g_free
(
basename
);
return
NULL
;
return
NULL
;
}
/* if we're adding directory paths, make sure to delete filenames
/* if we're adding directory paths, make sure to delete filenames
with potentially the same name */
with potentially the same name */
conflicting
=
songvec_find
(
&
parent
->
songs
,
mpd_basename
(
path
)
);
conflicting
=
songvec_find
(
&
parent
->
songs
,
basename
);
if
(
conflicting
)
if
(
conflicting
)
delete_song
(
parent
,
conflicting
);
delete_song
(
parent
,
conflicting
);
g_free
(
basename
);
directory
=
directory_new_child
(
parent
,
path
);
directory
=
directory_new_child
(
parent
,
path
);
directory_set_stat
(
directory
,
&
st
);
directory_set_stat
(
directory
,
&
st
);
return
directory
;
return
directory
;
...
@@ -455,19 +464,21 @@ static void
...
@@ -455,19 +464,21 @@ static void
updatePath
(
const
char
*
path
)
updatePath
(
const
char
*
path
)
{
{
struct
directory
*
parent
;
struct
directory
*
parent
;
c
onst
c
har
*
name
;
char
*
name
;
struct
stat
st
;
struct
stat
st
;
parent
=
addParentPathToDB
(
path
);
parent
=
addParentPathToDB
(
path
);
if
(
parent
==
NULL
)
if
(
parent
==
NULL
)
return
;
return
;
name
=
mpd
_basename
(
path
);
name
=
g_path_get
_basename
(
path
);
if
(
stat_directory_child
(
parent
,
name
,
&
st
)
==
0
)
if
(
stat_directory_child
(
parent
,
name
,
&
st
)
==
0
)
updateInDirectory
(
parent
,
name
,
&
st
);
updateInDirectory
(
parent
,
name
,
&
st
);
else
else
delete_name_in
(
parent
,
name
);
delete_name_in
(
parent
,
name
);
g_free
(
name
);
}
}
static
void
*
update_task
(
void
*
_path
)
static
void
*
update_task
(
void
*
_path
)
...
...
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