Spin-off syscall-related file operations (#78)

* [file_utils] spin-off syscall-related file operations

1. Eliminate the potential circular dependency between
   persistent-data/block.h and persistent-data/file_utils.h,
   if the former one wants to include the latter.
2. Avoid namespace pollution by removing the "using namespace std"
   declaration in block.tcc.
3. Correct the header hierarchy: base/xml_utils.h now no longer
   depends on the higher-level persistent-data/file_utils.h

* [file_utils] support block files in get_file_length()
This commit is contained in:
Ming-Hung Tsai
2017-04-30 01:51:52 +08:00
committed by Joe Thornber
parent 8f25e1b234
commit b7d418131d
20 changed files with 210 additions and 191 deletions

View File

@ -1,8 +1,9 @@
#include "xml_utils.h"
#include "persistent-data/file_utils.h"
#include "base/file_utils.h"
#include <fstream>
#include <iostream>
#include <sys/stat.h>
using namespace xml_utils;
@ -11,13 +12,13 @@ using namespace xml_utils;
void
xml_parser::parse(std::string const &backup_file, bool quiet)
{
persistent_data::check_file_exists(backup_file);
file_utils::check_file_exists(backup_file);
ifstream in(backup_file.c_str(), ifstream::in);
std::unique_ptr<base::progress_monitor> monitor = create_monitor(quiet);
size_t total = 0;
size_t input_length = get_file_length(backup_file);
size_t input_length = file_utils::get_file_length(backup_file);
XML_Error error_code = XML_ERROR_NONE;
while (!in.eof() && error_code == XML_ERROR_NONE) {
@ -43,19 +44,6 @@ xml_parser::parse(std::string const &backup_file, bool quiet)
}
}
size_t
xml_parser::get_file_length(string const &file) const
{
struct stat info;
int r;
r = ::stat(file.c_str(), &info);
if (r)
throw runtime_error("Couldn't stat backup path");
return info.st_size;
}
unique_ptr<base::progress_monitor>
xml_parser::create_monitor(bool quiet)
{