From bbe11e32eb22f77ce34f10b960e307df19bbc82d Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Fri, 5 Jan 2018 10:02:53 -0800 Subject: [PATCH] Prefer WriteToFile over manual std;:ofstream usage. --- src/cache_manager.cc | 6 +----- src/utils.cc | 5 +---- src/working_files.cc | 5 +++++ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/cache_manager.cc b/src/cache_manager.cc index cf21a545..9060482c 100644 --- a/src/cache_manager.cc +++ b/src/cache_manager.cc @@ -128,11 +128,7 @@ void WriteToCache(Config* config, IndexFile& file) { << "file-copy for " << file.path; CopyFileTo(cache_basename, file.path); } else { - std::ofstream cache_content; - cache_content.open(cache_basename); - assert(cache_content.good()); - cache_content << file.file_contents_; - cache_content.close(); + WriteToFile(cache_basename, file.file_contents_); } std::string indexed_content = Serialize(file); diff --git a/src/utils.cc b/src/utils.cc index ce6588b8..757e726e 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -450,10 +450,7 @@ void UpdateTestExpectation(const std::string& filename, str.replace(it, expectation.size(), actual); // Write it back out. - std::ofstream of(filename, - std::ios::out | std::ios::trunc | std::ios::binary); - of.write(str.c_str(), str.size()); - of.close(); + WriteToFile(filename, str); } void WriteToFile(const std::string& filename, const std::string& content) { diff --git a/src/working_files.cc b/src/working_files.cc index 19a4aeb4..e88d03d4 100644 --- a/src/working_files.cc +++ b/src/working_files.cc @@ -71,6 +71,11 @@ void WorkingFile::OnBufferContentUpdated() { else it->second.push_back(i + 1); } + + std::string path = filename; + path = ReplaceAll(path, "/", "_"); + WriteToFile("/usr/local/google/home/jdufault/cquery/tmp/" + path, + buffer_content); } optional WorkingFile::GetBufferLineFromIndexLine(int index_line) const {