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
c0ffec2f
Commit
c0ffec2f
authored
Mar 02, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
database: db_load() returns GError
Do error reporting with GLib's GError library.
parent
eb5b3ce5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
17 deletions
+48
-17
database.c
src/database.c
+40
-15
database.h
src/database.h
+3
-1
main.c
src/main.c
+5
-1
No files found.
src/database.c
View file @
c0ffec2f
...
...
@@ -49,6 +49,15 @@ static struct directory *music_root;
static
time_t
database_mtime
;
/**
* The quark used for GError.domain.
*/
static
inline
GQuark
db_quark
(
void
)
{
return
g_quark_from_static_string
(
"database"
);
}
void
db_init
(
const
char
*
path
)
{
...
...
@@ -267,7 +276,7 @@ db_save(void)
}
bool
db_load
(
void
)
db_load
(
GError
**
error
)
{
FILE
*
fp
=
NULL
;
struct
stat
st
;
...
...
@@ -281,21 +290,24 @@ db_load(void)
music_root
=
directory_new
(
""
,
NULL
);
while
(
!
(
fp
=
fopen
(
database_path
,
"r"
))
&&
errno
==
EINTR
)
;
if
(
fp
==
NULL
)
{
g_warning
(
"unable to open db file
\"
%s
\"
: %s"
,
database_path
,
strerror
(
errno
));
g_set_error
(
error
,
db_quark
(),
errno
,
"Failed to open database file
\"
%s
\"
: %s"
,
database_path
,
strerror
(
errno
));
return
false
;
}
/* get initial info */
if
(
!
fgets
(
buffer
,
sizeof
(
buffer
),
fp
))
g_error
(
"Error reading db, fgets"
);
if
(
!
fgets
(
buffer
,
sizeof
(
buffer
),
fp
))
{
fclose
(
fp
);
g_set_error
(
error
,
db_quark
(),
0
,
"Unexpected end of file"
);
return
false
;
}
g_strchomp
(
buffer
);
if
(
0
!=
strcmp
(
DIRECTORY_INFO_BEGIN
,
buffer
))
{
g_warning
(
"db info not found in db file; "
"you should recreate the db using --create-db"
);
while
(
fclose
(
fp
)
&&
errno
==
EINTR
)
;
fclose
(
fp
);
g_set_error
(
error
,
db_quark
(),
0
,
"Database corrupted"
);
return
false
;
}
...
...
@@ -304,14 +316,23 @@ db_load(void)
g_strchomp
(
buffer
);
if
(
g_str_has_prefix
(
buffer
,
DIRECTORY_MPD_VERSION
))
{
if
(
found_version
)
g_error
(
"already found version in db"
);
if
(
found_version
)
{
fclose
(
fp
);
g_set_error
(
error
,
db_quark
(),
0
,
"Duplicate version line"
);
return
false
;
}
found_version
=
true
;
}
else
if
(
g_str_has_prefix
(
buffer
,
DIRECTORY_FS_CHARSET
))
{
const
char
*
new_charset
,
*
old_charset
;
if
(
found_charset
)
g_error
(
"already found fs charset in db"
);
if
(
found_charset
)
{
fclose
(
fp
);
g_set_error
(
error
,
db_quark
(),
0
,
"Duplicate charset line"
);
return
false
;
}
found_charset
=
true
;
...
...
@@ -319,15 +340,19 @@ db_load(void)
old_charset
=
path_get_fs_charset
();
if
(
old_charset
!=
NULL
&&
strcmp
(
new_charset
,
old_charset
))
{
fclose
(
fp
);
g_message
(
"Existing database has charset
\"
%s
\"
"
"instead of
\"
%s
\"
; "
"discarding database file"
,
new_charset
,
old_charset
);
return
false
;
}
}
else
g_error
(
"unknown line in db info: %s"
,
buffer
);
}
else
{
fclose
(
fp
);
g_set_error
(
error
,
db_quark
(),
0
,
"Malformed line: %s"
,
buffer
);
return
false
;
}
}
g_debug
(
"reading DB"
);
...
...
src/database.h
View file @
c0ffec2f
...
...
@@ -20,6 +20,8 @@
#ifndef MPD_DATABASE_H
#define MPD_DATABASE_H
#include <glib.h>
#include <sys/time.h>
#include <stdbool.h>
...
...
@@ -66,7 +68,7 @@ bool
db_save
(
void
);
bool
db_load
(
void
);
db_load
(
GError
**
error
);
time_t
db_get_mtime
(
void
);
...
...
src/main.c
View file @
c0ffec2f
...
...
@@ -94,6 +94,7 @@ openDB(const Options *options)
{
const
char
*
path
=
config_get_path
(
CONF_DB_FILE
);
bool
ret
;
GError
*
error
=
NULL
;
if
(
!
mapper_has_music_directory
())
{
if
(
path
!=
NULL
)
...
...
@@ -112,8 +113,11 @@ openDB(const Options *options)
/* don't attempt to load the old database */
return
false
;
ret
=
db_load
();
ret
=
db_load
(
&
error
);
if
(
!
ret
)
{
g_warning
(
"Failed to load database: %s"
,
error
->
message
);
g_error_free
(
error
);
if
(
options
->
createDB
<
0
)
g_error
(
"can't open db file and using "
"
\"
--no-create-db
\"
command line option"
);
...
...
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