aboutsummaryrefslogtreecommitdiffstats
path: root/src/DatabaseSave.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/DatabaseSave.cxx (renamed from src/db_save.c)34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/db_save.c b/src/DatabaseSave.cxx
index 4af9d58b8..5100c2a0b 100644
--- a/src/db_save.c
+++ b/src/DatabaseSave.cxx
@@ -18,15 +18,18 @@
*/
#include "config.h"
-#include "db_save.h"
-#include "db_lock.h"
-#include "directory.h"
-#include "directory_save.h"
+#include "DatabaseSave.hxx"
+#include "DatabaseLock.hxx"
+#include "Directory.hxx"
+#include "DirectorySave.hxx"
#include "song.h"
-#include "path.h"
-#include "text_file.h"
+#include "TextFile.hxx"
+#include "TagInternal.hxx"
#include "tag.h"
-#include "tag_internal.h"
+
+extern "C" {
+#include "path.h"
+}
#include <glib.h>
@@ -55,7 +58,7 @@ db_quark(void)
}
void
-db_save_internal(FILE *fp, const struct directory *music_root)
+db_save_internal(FILE *fp, const Directory *music_root)
{
assert(music_root != NULL);
@@ -74,9 +77,8 @@ db_save_internal(FILE *fp, const struct directory *music_root)
}
bool
-db_load_internal(FILE *fp, struct 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;
@@ -86,16 +88,15 @@ db_load_internal(FILE *fp, struct 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);
@@ -103,7 +104,6 @@ db_load_internal(FILE *fp, struct 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;
}
@@ -114,7 +114,6 @@ db_load_internal(FILE *fp, struct 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;
}
@@ -129,7 +128,6 @@ db_load_internal(FILE *fp, struct 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)) {
@@ -147,7 +145,6 @@ db_load_internal(FILE *fp, struct directory *music_root, GError **error)
} else {
g_set_error(error, db_quark(), 0,
"Malformed line: %s", line);
- g_string_free(buffer, true);
return false;
}
}
@@ -171,9 +168,8 @@ db_load_internal(FILE *fp, struct 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;
}