aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-02-24 23:14:14 +0100
committerMax Kellermann <max@duempel.org>2014-02-25 18:15:43 +0100
commit8963cd1fabbe9cb54a5f246844b3fd5b1ac332cf (patch)
tree8dd4b1e858dd954ae2bdf7a2097b63bcb053ea45 /src
parent55cd5a9a7894a0b92d321721ce8c049cfd4b5112 (diff)
downloadmpd-8963cd1fabbe9cb54a5f246844b3fd5b1ac332cf.tar.gz
mpd-8963cd1fabbe9cb54a5f246844b3fd5b1ac332cf.tar.xz
mpd-8963cd1fabbe9cb54a5f246844b3fd5b1ac332cf.zip
DirectorySave: move code to ParseLine()
Diffstat (limited to '')
-rw-r--r--src/db/DirectorySave.cxx40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/db/DirectorySave.cxx b/src/db/DirectorySave.cxx
index 614473d34..30b96aa5a 100644
--- a/src/db/DirectorySave.cxx
+++ b/src/db/DirectorySave.cxx
@@ -70,6 +70,18 @@ directory_save(FILE *fp, const Directory &directory)
fprintf(fp, DIRECTORY_END "%s\n", directory.GetPath());
}
+static bool
+ParseLine(Directory &directory, const char *line)
+{
+ if (StringStartsWith(line, DIRECTORY_MTIME)) {
+ directory.mtime =
+ ParseUint64(line + sizeof(DIRECTORY_MTIME) - 1);
+ } else
+ return false;
+
+ return true;
+}
+
static Directory *
directory_load_subdir(TextFile &file, Directory &parent, const char *name,
Error &error)
@@ -84,29 +96,23 @@ directory_load_subdir(TextFile &file, Directory &parent, const char *name,
Directory *directory = parent.CreateChild(name);
- const char *line = file.ReadLine();
- if (line == nullptr) {
- error.Set(directory_domain, "Unexpected end of file");
- directory->Delete();
- return nullptr;
- }
-
- if (StringStartsWith(line, DIRECTORY_MTIME)) {
- directory->mtime =
- ParseUint64(line + sizeof(DIRECTORY_MTIME) - 1);
-
- line = file.ReadLine();
+ while (true) {
+ const char *line = file.ReadLine();
if (line == nullptr) {
error.Set(directory_domain, "Unexpected end of file");
directory->Delete();
return nullptr;
}
- }
- if (!StringStartsWith(line, DIRECTORY_BEGIN)) {
- error.Format(directory_domain, "Malformed line: %s", line);
- directory->Delete();
- return nullptr;
+ if (StringStartsWith(line, DIRECTORY_BEGIN))
+ break;
+
+ if (!ParseLine(*directory, line)) {
+ error.Format(directory_domain,
+ "Malformed line: %s", line);
+ directory->Delete();
+ return nullptr;
+ }
}
success = directory_load(file, *directory, error);