diff options
author | Max Kellermann <max@duempel.org> | 2013-01-03 10:16:05 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-01-03 10:16:05 +0100 |
commit | 90fe4c5124e3fd335f05804d3cc47ba996e62b14 (patch) | |
tree | ef7fb6b3cb2edbe4898431db611f04fb281129fc /src/DatabaseSave.cxx | |
parent | 2452447c814048ed72e95a459c76b4be65962b5c (diff) | |
download | mpd-90fe4c5124e3fd335f05804d3cc47ba996e62b14.tar.gz mpd-90fe4c5124e3fd335f05804d3cc47ba996e62b14.tar.xz mpd-90fe4c5124e3fd335f05804d3cc47ba996e62b14.zip |
TextFile: convert to a class
Diffstat (limited to '')
-rw-r--r-- | src/DatabaseSave.cxx | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/src/DatabaseSave.cxx b/src/DatabaseSave.cxx index 5bd50f55f..78a2c4939 100644 --- a/src/DatabaseSave.cxx +++ b/src/DatabaseSave.cxx @@ -77,9 +77,8 @@ db_save_internal(FILE *fp, const Directory *music_root) } bool -db_load_internal(FILE *fp, Directory *music_root, GError **error) +db_load_internal(TextFile &file, Directory *music_root, GError **error) { - GString *buffer = g_string_sized_new(1024); char *line; int format = 0; bool found_charset = false, found_version = false; @@ -89,16 +88,15 @@ db_load_internal(FILE *fp, Directory *music_root, GError **error) assert(music_root != NULL); /* get initial info */ - line = read_text_line(fp, buffer); + line = file.ReadLine(); if (line == NULL || strcmp(DIRECTORY_INFO_BEGIN, line) != 0) { g_set_error(error, db_quark(), 0, "Database corrupted"); - g_string_free(buffer, true); return false; } memset(tags, false, sizeof(tags)); - while ((line = read_text_line(fp, buffer)) != NULL && + while ((line = file.ReadLine()) != NULL && strcmp(line, DIRECTORY_INFO_END) != 0) { if (g_str_has_prefix(line, DB_FORMAT_PREFIX)) { format = atoi(line + sizeof(DB_FORMAT_PREFIX) - 1); @@ -106,7 +104,6 @@ db_load_internal(FILE *fp, Directory *music_root, GError **error) if (found_version) { g_set_error(error, db_quark(), 0, "Duplicate version line"); - g_string_free(buffer, true); return false; } @@ -117,7 +114,6 @@ db_load_internal(FILE *fp, Directory *music_root, GError **error) if (found_charset) { g_set_error(error, db_quark(), 0, "Duplicate charset line"); - g_string_free(buffer, true); return false; } @@ -132,7 +128,6 @@ db_load_internal(FILE *fp, Directory *music_root, GError **error) "\"%s\" instead of \"%s\"; " "discarding database file", new_charset, old_charset); - g_string_free(buffer, true); return false; } } else if (g_str_has_prefix(line, DB_TAG_PREFIX)) { @@ -150,7 +145,6 @@ db_load_internal(FILE *fp, Directory *music_root, GError **error) } else { g_set_error(error, db_quark(), 0, "Malformed line: %s", line); - g_string_free(buffer, true); return false; } } @@ -174,9 +168,8 @@ db_load_internal(FILE *fp, Directory *music_root, GError **error) g_debug("reading DB"); db_lock(); - success = directory_load(fp, music_root, buffer, error); + success = directory_load(file, music_root, error); db_unlock(); - g_string_free(buffer, true); return success; } |