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
a1561252
Commit
a1561252
authored
Mar 02, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
directory: directory_load() returns GError
Do error reporting with GLib's GError library in this library, too.
parent
c0ffec2f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
19 deletions
+53
-19
database.c
src/database.c
+5
-1
directory_save.c
src/directory_save.c
+43
-16
directory_save.h
src/directory_save.h
+5
-2
No files found.
src/database.c
View file @
a1561252
...
...
@@ -282,6 +282,7 @@ db_load(GError **error)
struct
stat
st
;
char
buffer
[
100
];
bool
found_charset
=
false
,
found_version
=
false
;
bool
success
;
assert
(
database_path
!=
NULL
);
assert
(
music_root
!=
NULL
);
...
...
@@ -357,9 +358,12 @@ db_load(GError **error)
g_debug
(
"reading DB"
);
directory_load
(
fp
,
music_root
);
success
=
directory_load
(
fp
,
music_root
,
error
);
while
(
fclose
(
fp
)
&&
errno
==
EINTR
)
;
if
(
!
success
)
return
false
;
stats_update
();
if
(
stat
(
database_path
,
&
st
)
==
0
)
...
...
src/directory_save.c
View file @
a1561252
...
...
@@ -19,12 +19,9 @@
#include "directory_save.h"
#include "directory.h"
#include "song.h"
#include "log.h"
#include "path.h"
#include "song_save.h"
#include <glib.h>
#include <assert.h>
#include <string.h>
...
...
@@ -32,6 +29,15 @@
#define DIRECTORY_BEGIN "begin: "
#define DIRECTORY_END "end: "
/**
* The quark used for GError.domain.
*/
static
inline
GQuark
directory_quark
(
void
)
{
return
g_quark_from_static_string
(
"directory"
);
}
/* TODO error checking */
int
directory_save
(
FILE
*
fp
,
struct
directory
*
directory
)
...
...
@@ -71,12 +77,13 @@ directory_save(FILE *fp, struct directory *directory)
return
0
;
}
void
directory_load
(
FILE
*
fp
,
struct
directory
*
directory
)
bool
directory_load
(
FILE
*
fp
,
struct
directory
*
directory
,
GError
**
error
)
{
char
buffer
[
MPD_PATH_MAX
*
2
];
char
key
[
MPD_PATH_MAX
*
2
];
char
*
name
;
bool
success
;
while
(
fgets
(
buffer
,
sizeof
(
buffer
),
fp
)
&&
!
g_str_has_prefix
(
buffer
,
DIRECTORY_END
))
{
...
...
@@ -85,25 +92,38 @@ directory_load(FILE *fp, struct directory *directory)
g_strchomp
(
buffer
);
strcpy
(
key
,
&
(
buffer
[
strlen
(
DIRECTORY_DIR
)]));
if
(
!
fgets
(
buffer
,
sizeof
(
buffer
),
fp
))
FATAL
(
"Error reading db, fgets
\n
"
);
if
(
!
fgets
(
buffer
,
sizeof
(
buffer
),
fp
))
{
g_set_error
(
error
,
directory_quark
(),
0
,
"Unexpected end of file"
);
return
false
;
}
if
(
g_str_has_prefix
(
buffer
,
DIRECTORY_MTIME
))
{
directory
->
mtime
=
g_ascii_strtoull
(
buffer
+
sizeof
(
DIRECTORY_MTIME
)
-
1
,
NULL
,
10
);
if
(
!
fgets
(
buffer
,
sizeof
(
buffer
),
fp
))
FATAL
(
"Error reading db, fgets
\n
"
);
if
(
!
fgets
(
buffer
,
sizeof
(
buffer
),
fp
))
{
g_set_error
(
error
,
directory_quark
(),
0
,
"Unexpected end of file"
);
return
false
;
}
}
if
(
!
g_str_has_prefix
(
buffer
,
DIRECTORY_BEGIN
))
{
g_set_error
(
error
,
directory_quark
(),
0
,
"Malformed line: %s"
,
buffer
);
return
false
;
}
if
(
!
g_str_has_prefix
(
buffer
,
DIRECTORY_BEGIN
))
FATAL
(
"Error reading db at line: %s
\n
"
,
buffer
);
g_strchomp
(
buffer
);
name
=
&
(
buffer
[
strlen
(
DIRECTORY_BEGIN
)]);
if
(
!
g_str_has_prefix
(
name
,
directory
->
path
)
!=
0
)
FATAL
(
"Wrong path in database: '%s' in '%s'
\n
"
,
name
,
directory
->
path
);
if
(
!
g_str_has_prefix
(
name
,
directory
->
path
)
!=
0
)
{
g_set_error
(
error
,
directory_quark
(),
0
,
"Wrong path in database: '%s' in '%s'"
,
name
,
directory
->
path
);
return
false
;
}
subdir
=
directory_get_child
(
directory
,
name
);
if
(
subdir
!=
NULL
)
{
...
...
@@ -112,11 +132,18 @@ directory_load(FILE *fp, struct directory *directory)
subdir
=
directory_new
(
name
,
directory
);
dirvec_add
(
&
directory
->
children
,
subdir
);
}
directory_load
(
fp
,
subdir
);
success
=
directory_load
(
fp
,
subdir
,
error
);
if
(
!
success
)
return
false
;
}
else
if
(
g_str_has_prefix
(
buffer
,
SONG_BEGIN
))
{
readSongInfoIntoList
(
fp
,
&
directory
->
songs
,
directory
);
}
else
{
FATAL
(
"Unknown line in db: %s
\n
"
,
buffer
);
g_set_error
(
error
,
directory_quark
(),
0
,
"Malformed line: %s"
,
buffer
);
return
false
;
}
}
return
true
;
}
src/directory_save.h
View file @
a1561252
...
...
@@ -19,6 +19,9 @@
#ifndef MPD_DIRECTORY_SAVE_H
#define MPD_DIRECTORY_SAVE_H
#include <glib.h>
#include <stdbool.h>
#include <stdio.h>
struct
directory
;
...
...
@@ -26,7 +29,7 @@ struct directory;
int
directory_save
(
FILE
*
fp
,
struct
directory
*
directory
);
void
directory_load
(
FILE
*
fp
,
struct
directory
*
directory
);
bool
directory_load
(
FILE
*
fp
,
struct
directory
*
directory
,
GError
**
error
);
#endif
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