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
49260e6d
Commit
49260e6d
authored
Oct 20, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
path: replaced parent_path() with g_path_get_dirname()
Again, GLib's version is more robust than ours.
parent
ba96920a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
42 deletions
+7
-42
database.c
src/database.c
+7
-4
path.c
src/path.c
+0
-28
path.h
src/path.h
+0
-10
No files found.
src/database.c
View file @
49260e6d
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
#include <assert.h>
#include <assert.h>
#include <string.h>
#include <string.h>
#include <glib.h>
static
struct
directory
*
music_root
;
static
struct
directory
*
music_root
;
...
@@ -151,19 +152,18 @@ db_check(void)
...
@@ -151,19 +152,18 @@ db_check(void)
/* If the file doesn't exist, we can't check if we can write
/* If the file doesn't exist, we can't check if we can write
* it, so we are going to try to get the directory path, and
* it, so we are going to try to get the directory path, and
* see if we can write a file in that */
* see if we can write a file in that */
char
dirPath
[
MPD_PATH_MAX
];
char
*
dirPath
=
g_path_get_dirname
(
dbFile
);
parent_path
(
dirPath
,
dbFile
);
if
(
*
dirPath
==
'\0'
)
strcpy
(
dirPath
,
"/"
);
/* Check that the parent part of the path is a directory */
/* Check that the parent part of the path is a directory */
if
(
stat
(
dirPath
,
&
st
)
<
0
)
{
if
(
stat
(
dirPath
,
&
st
)
<
0
)
{
g_free
(
dirPath
);
ERROR
(
"Couldn't stat parent directory of db file "
ERROR
(
"Couldn't stat parent directory of db file "
"
\"
%s
\"
: %s
\n
"
,
dbFile
,
strerror
(
errno
));
"
\"
%s
\"
: %s
\n
"
,
dbFile
,
strerror
(
errno
));
return
-
1
;
return
-
1
;
}
}
if
(
!
S_ISDIR
(
st
.
st_mode
))
{
if
(
!
S_ISDIR
(
st
.
st_mode
))
{
g_free
(
dirPath
);
ERROR
(
"Couldn't create db file
\"
%s
\"
because the "
ERROR
(
"Couldn't create db file
\"
%s
\"
because the "
"parent path is not a directory
\n
"
,
dbFile
);
"parent path is not a directory
\n
"
,
dbFile
);
return
-
1
;
return
-
1
;
...
@@ -173,9 +173,12 @@ db_check(void)
...
@@ -173,9 +173,12 @@ db_check(void)
if
(
access
(
dirPath
,
R_OK
|
W_OK
))
{
if
(
access
(
dirPath
,
R_OK
|
W_OK
))
{
ERROR
(
"Can't create db file in
\"
%s
\"
: %s
\n
"
,
dirPath
,
ERROR
(
"Can't create db file in
\"
%s
\"
: %s
\n
"
,
dirPath
,
strerror
(
errno
));
strerror
(
errno
));
g_free
(
dirPath
);
return
-
1
;
return
-
1
;
}
}
g_free
(
dirPath
);
return
0
;
return
0
;
}
}
...
...
src/path.c
View file @
49260e6d
...
@@ -202,34 +202,6 @@ void pathcpy_trunc(char *dest, const char *src)
...
@@ -202,34 +202,6 @@ void pathcpy_trunc(char *dest, const char *src)
dest
[
len
]
=
'\0'
;
dest
[
len
]
=
'\0'
;
}
}
char
*
parent_path
(
char
*
path_max_tmp
,
const
char
*
path
)
{
char
*
c
;
static
const
int
handle_trailing_slashes
=
0
;
pathcpy_trunc
(
path_max_tmp
,
path
);
if
(
handle_trailing_slashes
)
{
size_t
last_char
=
strlen
(
path_max_tmp
)
-
1
;
while
(
last_char
>
0
&&
path_max_tmp
[
last_char
]
==
'/'
)
path_max_tmp
[
last_char
--
]
=
'\0'
;
}
c
=
strrchr
(
path_max_tmp
,
'/'
);
if
(
c
==
NULL
)
path_max_tmp
[
0
]
=
'\0'
;
else
{
/* strip redundant slashes: */
while
((
path_max_tmp
<=
c
)
&&
*
(
--
c
)
==
'/'
)
/* nothing */
;
c
[
1
]
=
'\0'
;
}
return
path_max_tmp
;
}
char
*
sanitizePathDup
(
const
char
*
path
)
char
*
sanitizePathDup
(
const
char
*
path
)
{
{
int
len
=
strlen
(
path
)
+
1
;
int
len
=
strlen
(
path
)
+
1
;
...
...
src/path.h
View file @
49260e6d
...
@@ -58,16 +58,6 @@ char *pfx_dir(char *dst,
...
@@ -58,16 +58,6 @@ char *pfx_dir(char *dst,
/* relative playlist path to absolute playlist path */
/* relative playlist path to absolute playlist path */
char
*
rpp2app_r
(
char
*
dst
,
const
char
*
rel_path
);
char
*
rpp2app_r
(
char
*
dst
,
const
char
*
rel_path
);
/*
* parent_path - saner version of dirname(3) with slightly different semantics
* - we will return "" instead of "." or "/" if we have no parent
* this is because we only deal with internal paths
* - we always skip over redundant slashes in the middle, if there are any
* - we will never get meaningful paths with trailing slashes in our callers
* (set handle_trailing_slashes to true if we do)
*/
char
*
parent_path
(
char
*
path_max_tmp
,
const
char
*
path
);
/* strips extra "///" and leading "/" and trailing "/" */
/* strips extra "///" and leading "/" and trailing "/" */
char
*
sanitizePathDup
(
const
char
*
path
);
char
*
sanitizePathDup
(
const
char
*
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