Commit 8963cd1f authored by Max Kellermann's avatar Max Kellermann

DirectorySave: move code to ParseLine()

parent 55cd5a9a
......@@ -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,6 +96,7 @@ directory_load_subdir(TextFile &file, Directory &parent, const char *name,
Directory *directory = parent.CreateChild(name);
while (true) {
const char *line = file.ReadLine();
if (line == nullptr) {
error.Set(directory_domain, "Unexpected end of file");
......@@ -91,24 +104,17 @@ directory_load_subdir(TextFile &file, Directory &parent, const char *name,
return nullptr;
}
if (StringStartsWith(line, DIRECTORY_MTIME)) {
directory->mtime =
ParseUint64(line + sizeof(DIRECTORY_MTIME) - 1);
if (StringStartsWith(line, DIRECTORY_BEGIN))
break;
line = file.ReadLine();
if (line == nullptr) {
error.Set(directory_domain, "Unexpected end of file");
if (!ParseLine(*directory, line)) {
error.Format(directory_domain,
"Malformed line: %s", line);
directory->Delete();
return nullptr;
}
}
if (!StringStartsWith(line, DIRECTORY_BEGIN)) {
error.Format(directory_domain, "Malformed line: %s", line);
directory->Delete();
return nullptr;
}
success = directory_load(file, *directory, error);
if (!success) {
directory->Delete();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment