song_save: use GError for error handling
This commit is contained in:
parent
69ff9d757f
commit
111c4dac63
@ -138,7 +138,10 @@ directory_load(FILE *fp, struct directory *directory, GError **error)
|
|||||||
if (!success)
|
if (!success)
|
||||||
return false;
|
return false;
|
||||||
} else if (g_str_has_prefix(buffer, SONG_BEGIN)) {
|
} else if (g_str_has_prefix(buffer, SONG_BEGIN)) {
|
||||||
songvec_load(fp, &directory->songs, directory);
|
success = songvec_load(fp, &directory->songs,
|
||||||
|
directory, error);
|
||||||
|
if (!success)
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
g_set_error(error, directory_quark(), 0,
|
g_set_error(error, directory_quark(), 0,
|
||||||
"Malformed line: %s", buffer);
|
"Malformed line: %s", buffer);
|
||||||
|
@ -34,6 +34,12 @@
|
|||||||
#define SONG_KEY "key: "
|
#define SONG_KEY "key: "
|
||||||
#define SONG_MTIME "mtime: "
|
#define SONG_MTIME "mtime: "
|
||||||
|
|
||||||
|
static GQuark
|
||||||
|
song_save_quark(void)
|
||||||
|
{
|
||||||
|
return g_quark_from_static_string("song_save");
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
song_save_url(FILE *fp, struct song *song)
|
song_save_url(FILE *fp, struct song *song)
|
||||||
{
|
{
|
||||||
@ -110,8 +116,9 @@ parse_tag_value(char *buffer, enum tag_type *type_r)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
songvec_load(FILE *fp, struct songvec *sv, struct directory *parent)
|
songvec_load(FILE *fp, struct songvec *sv, struct directory *parent,
|
||||||
|
GError **error_r)
|
||||||
{
|
{
|
||||||
char buffer[MPD_PATH_MAX + 1024];
|
char buffer[MPD_PATH_MAX + 1024];
|
||||||
struct song *song = NULL;
|
struct song *song = NULL;
|
||||||
@ -131,7 +138,9 @@ songvec_load(FILE *fp, struct songvec *sv, struct directory *parent)
|
|||||||
} else if (*buffer == 0) {
|
} else if (*buffer == 0) {
|
||||||
/* ignore empty lines (starting with '\0') */
|
/* ignore empty lines (starting with '\0') */
|
||||||
} else if (song == NULL) {
|
} else if (song == NULL) {
|
||||||
g_error("Problems reading song info");
|
g_set_error(error_r, song_save_quark(), 0,
|
||||||
|
"Problems reading song info");
|
||||||
|
return false;
|
||||||
} else if (0 == strncmp(SONG_FILE, buffer, strlen(SONG_FILE))) {
|
} else if (0 == strncmp(SONG_FILE, buffer, strlen(SONG_FILE))) {
|
||||||
/* we don't need this info anymore */
|
/* we don't need this info anymore */
|
||||||
} else if ((value = parse_tag_value(buffer,
|
} else if ((value = parse_tag_value(buffer,
|
||||||
@ -151,11 +160,15 @@ songvec_load(FILE *fp, struct songvec *sv, struct directory *parent)
|
|||||||
song->tag->time = atoi(&(buffer[strlen(SONG_TIME)]));
|
song->tag->time = atoi(&(buffer[strlen(SONG_TIME)]));
|
||||||
} else if (0 == strncmp(SONG_MTIME, buffer, strlen(SONG_MTIME))) {
|
} else if (0 == strncmp(SONG_MTIME, buffer, strlen(SONG_MTIME))) {
|
||||||
song->mtime = atoi(&(buffer[strlen(SONG_MTIME)]));
|
song->mtime = atoi(&(buffer[strlen(SONG_MTIME)]));
|
||||||
|
} else {
|
||||||
|
g_set_error(error_r, song_save_quark(), 0,
|
||||||
|
"unknown line in db: %s", buffer);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
g_error("unknown line in db: %s", buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (song)
|
if (song)
|
||||||
commit_song(sv, song);
|
commit_song(sv, song);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
#ifndef MPD_SONG_SAVE_H
|
#ifndef MPD_SONG_SAVE_H
|
||||||
#define MPD_SONG_SAVE_H
|
#define MPD_SONG_SAVE_H
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
struct songvec;
|
struct songvec;
|
||||||
@ -27,7 +30,16 @@ struct directory;
|
|||||||
|
|
||||||
void songvec_save(FILE *fp, struct songvec *sv);
|
void songvec_save(FILE *fp, struct songvec *sv);
|
||||||
|
|
||||||
void
|
/**
|
||||||
songvec_load(FILE *fp, struct songvec *sv, struct directory *parent);
|
* Loads songs from the input file and add the to the specified
|
||||||
|
* directory.
|
||||||
|
*
|
||||||
|
* @param error_r location to store the error occuring, or NULL to
|
||||||
|
* ignore errors
|
||||||
|
* @return true on success, false on error
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
songvec_load(FILE *file, struct songvec *sv, struct directory *parent,
|
||||||
|
GError **error_r);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user