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
68875ba6
Commit
68875ba6
authored
Sep 09, 2011
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
database: return GError on failure
parent
2119a16e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
23 deletions
+41
-23
database.c
src/database.c
+28
-17
database.h
src/database.h
+2
-2
main.c
src/main.c
+3
-2
update.c
src/update.c
+8
-2
No files found.
src/database.c
View file @
68875ba6
...
...
@@ -151,7 +151,7 @@ db_walk(const char *name,
}
bool
db_check
(
void
)
db_check
(
GError
**
error_r
)
{
struct
stat
st
;
...
...
@@ -167,22 +167,27 @@ db_check(void)
/* Check that the parent part of the path is a directory */
if
(
stat
(
dirPath
,
&
st
)
<
0
)
{
g_free
(
dirPath
);
g_warning
(
"Couldn't stat parent directory of db file "
"
\"
%s
\"
: %s"
,
database_path
,
strerror
(
errno
));
g_set_error
(
error_r
,
db_quark
(),
errno
,
"Couldn't stat parent directory of db file "
"
\"
%s
\"
: %s"
,
database_path
,
g_strerror
(
errno
));
return
false
;
}
if
(
!
S_ISDIR
(
st
.
st_mode
))
{
g_free
(
dirPath
);
g_warning
(
"Couldn't create db file
\"
%s
\"
because the "
"parent path is not a directory"
,
database_path
);
g_set_error
(
error_r
,
db_quark
(),
0
,
"Couldn't create db file
\"
%s
\"
because the "
"parent path is not a directory"
,
database_path
);
return
false
;
}
/* Check if we can write to the directory */
if
(
access
(
dirPath
,
X_OK
|
W_OK
))
{
g_warning
(
"Can't create db file in
\"
%s
\"
: %s"
,
dirPath
,
strerror
(
errno
));
g_set_error
(
error_r
,
db_quark
(),
errno
,
"Can't create db file in
\"
%s
\"
: %s"
,
dirPath
,
g_strerror
(
errno
));
g_free
(
dirPath
);
return
false
;
}
...
...
@@ -194,20 +199,24 @@ db_check(void)
/* Path exists, now check if it's a regular file */
if
(
stat
(
database_path
,
&
st
)
<
0
)
{
g_warning
(
"Couldn't stat db file
\"
%s
\"
: %s"
,
database_path
,
strerror
(
errno
));
g_set_error
(
error_r
,
db_quark
(),
errno
,
"Couldn't stat db file
\"
%s
\"
: %s"
,
database_path
,
g_strerror
(
errno
));
return
false
;
}
if
(
!
S_ISREG
(
st
.
st_mode
))
{
g_warning
(
"db file
\"
%s
\"
is not a regular file"
,
database_path
);
g_set_error
(
error_r
,
db_quark
(),
0
,
"db file
\"
%s
\"
is not a regular file"
,
database_path
);
return
false
;
}
/* And check that we can write to it */
if
(
access
(
database_path
,
R_OK
|
W_OK
))
{
g_warning
(
"Can't open db file
\"
%s
\"
for reading/writing: %s"
,
database_path
,
strerror
(
errno
));
g_set_error
(
error_r
,
db_quark
(),
errno
,
"Can't open db file
\"
%s
\"
for reading/writing: %s"
,
database_path
,
g_strerror
(
errno
));
return
false
;
}
...
...
@@ -215,7 +224,7 @@ db_check(void)
}
bool
db_save
(
void
)
db_save
(
GError
**
error_r
)
{
FILE
*
fp
;
struct
stat
st
;
...
...
@@ -234,8 +243,9 @@ db_save(void)
fp
=
fopen
(
database_path
,
"w"
);
if
(
!
fp
)
{
g_warning
(
"unable to write to db file
\"
%s
\"
: %s"
,
database_path
,
strerror
(
errno
));
g_set_error
(
error_r
,
db_quark
(),
errno
,
"unable to write to db file
\"
%s
\"
: %s"
,
database_path
,
g_strerror
(
errno
));
return
false
;
}
...
...
@@ -253,8 +263,9 @@ db_save(void)
directory_save
(
fp
,
music_root
);
if
(
ferror
(
fp
))
{
g_warning
(
"Failed to write to database file: %s"
,
strerror
(
errno
));
g_set_error
(
error_r
,
db_quark
(),
errno
,
"Failed to write to database file: %s"
,
g_strerror
(
errno
));
fclose
(
fp
);
return
false
;
}
...
...
src/database.h
View file @
68875ba6
...
...
@@ -62,10 +62,10 @@ int db_walk(const char *name,
int
(
*
forEachDir
)(
struct
directory
*
,
void
*
),
void
*
data
);
bool
db_check
(
void
);
db_check
(
GError
**
error_r
);
bool
db_save
(
void
);
db_save
(
GError
**
error_r
);
bool
db_load
(
GError
**
error
);
...
...
src/main.c
View file @
68875ba6
...
...
@@ -182,9 +182,10 @@ glue_db_init_and_load(void)
if
(
!
ret
)
{
g_warning
(
"Failed to load database: %s"
,
error
->
message
);
g_error_free
(
error
);
error
=
NULL
;
if
(
!
db_check
())
exit
(
EXIT_FAILURE
);
if
(
!
db_check
(
&
error
))
MPD_ERROR
(
"%s"
,
error
->
message
);
db_clear
();
...
...
src/update.c
View file @
68875ba6
...
...
@@ -68,8 +68,14 @@ static void * update_task(void *_path)
modified
=
update_walk
(
path
,
discard
);
if
(
modified
||
!
db_exists
())
db_save
();
if
(
modified
||
!
db_exists
())
{
GError
*
error
=
NULL
;
if
(
!
db_save
(
&
error
))
{
g_warning
(
"Failed to save database: %s"
,
error
->
message
);
g_error_free
(
error
);
}
}
if
(
path
!=
NULL
&&
*
path
!=
0
)
g_debug
(
"finished: %s"
,
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