Index: tools/gn/visual_studio_writer.cc |
diff --git a/tools/gn/visual_studio_writer.cc b/tools/gn/visual_studio_writer.cc |
index 968e046b72fb129979ea276b5fe8cb0f5cc0aabb..c23db55398e6099d530de76505af085e31f05457 100644 |
--- a/tools/gn/visual_studio_writer.cc |
+++ b/tools/gn/visual_studio_writer.cc |
@@ -9,7 +9,6 @@ |
#include <set> |
#include <string> |
-#include "base/files/file_util.h" |
#include "base/logging.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/strings/string_util.h" |
@@ -153,26 +152,6 @@ base::StringPiece FindParentDir(const std::string* path) { |
return base::StringPiece(); |
} |
-bool HasSameContent(std::stringstream& data_1, const base::FilePath& data_2) { |
- // Compare file sizes first. Quick and will save us some time if they are |
- // different sizes. |
- int64_t data_1_len = data_1.tellp(); |
- |
- int64_t data_2_len; |
- if (!base::GetFileSize(data_2, &data_2_len) || data_1_len != data_2_len) |
- return false; |
- |
- std::string data_2_data; |
- data_2_data.resize(data_2_len); |
- if (!base::ReadFileToString(data_2, &data_2_data)) |
- return false; |
- |
- std::string data_1_data; |
- data_1_data = data_1.str(); |
- |
- return data_1_data == data_2_data; |
-} |
- |
} // namespace |
VisualStudioWriter::SolutionEntry::SolutionEntry(const std::string& _name, |
@@ -265,14 +244,10 @@ bool VisualStudioWriter::WriteProjectFiles(const Target* target, Err* err) { |
// Only write the content to the file if it's different. That is |
// both a performance optimization and more importantly, prevents |
// Visual Studio from reloading the projects. |
- if (!HasSameContent(vcxproj_string_out, vcxproj_path)) { |
- std::string content = vcxproj_string_out.str(); |
- int size = static_cast<int>(content.size()); |
- if (base::WriteFile(vcxproj_path, content.c_str(), size) != size) { |
- *err = Err(Location(), "Couldn't open " + target->label().name() + |
- ".vcxproj for writing"); |
- return false; |
- } |
+ if (!WriteFileIfChanged(vcxproj_path, &vcxproj_string_out)) { |
+ *err = Err(Location(), |
+ "Couldn't write " + target->label().name() + ".vcxproj"); |
+ return false; |
} |
base::FilePath filters_path = UTF8ToFilePath(vcxproj_path_str + ".filters"); |
@@ -280,14 +255,9 @@ bool VisualStudioWriter::WriteProjectFiles(const Target* target, Err* err) { |
std::stringstream filters_string_out; |
WriteFiltersFileContents(filters_string_out, target); |
- if (!HasSameContent(filters_string_out, filters_path)) { |
- std::string content = filters_string_out.str(); |
- int size = static_cast<int>(content.size()); |
- if (base::WriteFile(filters_path, content.c_str(), size) != size) { |
- *err = Err(Location(), "Couldn't open " + target->label().name() + |
- ".vcxproj.filters for writing"); |
- return false; |
- } |
+ if (!WriteFileIfChanged(filters_path, &filters_string_out)) { |
+ *err = Err(Location(), |
+ "Couldn't write " + target->label().name() + ".vcxproj.filters"); |
} |
return true; |
@@ -586,13 +556,8 @@ bool VisualStudioWriter::WriteSolutionFile(Err* err) { |
// Only write the content to the file if it's different. That is |
// both a performance optimization and more importantly, prevents |
// Visual Studio from reloading the projects. |
- if (HasSameContent(string_out, sln_path)) |
- return true; |
- |
- std::string content = string_out.str(); |
- int size = static_cast<int>(content.size()); |
- if (base::WriteFile(sln_path, content.c_str(), size) != size) { |
- *err = Err(Location(), "Couldn't open all.sln for writing"); |
+ if (!WriteFileIfChanged(sln_path, &string_out)) { |
+ *err = Err(Location(), "Couldn't write all.sln"); |
return false; |
} |