Index: tools/gn/filesystem_utils.cc |
diff --git a/tools/gn/filesystem_utils.cc b/tools/gn/filesystem_utils.cc |
index 5905cdb9f1ec73749a03e15428d5109542712b22..870438405934402d537746fbeef6ee6c60b59fd6 100644 |
--- a/tools/gn/filesystem_utils.cc |
+++ b/tools/gn/filesystem_utils.cc |
@@ -687,6 +687,33 @@ std::string GetOutputSubdirName(const Label& toolchain_label, bool is_default) { |
return toolchain_label.name() + "/"; |
} |
+bool ContentsEqual(const base::FilePath& file_path, std::stringstream* data) { |
brettw
2016/02/02 20:50:23
I'm thinking it might be better if this took a std
Tomasz Moniuszko
2016/02/03 10:20:30
Done.
|
+ // Compare file and stream sizes first. Quick and will save us some time if |
+ // they are different sizes. |
+ int64_t data_size = data->tellp(); |
+ |
+ int64_t file_size; |
+ if (!base::GetFileSize(file_path, &file_size) || file_size != data_size) |
+ return false; |
+ |
+ std::string file_data; |
+ file_data.resize(file_size); |
+ if (!base::ReadFileToString(file_path, &file_data)) |
+ return false; |
+ |
+ return file_data == data->str(); |
+} |
+ |
+bool WriteFileIfChanged(const base::FilePath& file_path, |
+ std::stringstream* data) { |
+ if (ContentsEqual(file_path, data)) |
+ return true; |
+ |
+ std::string data_str = data->str(); |
+ int size = static_cast<int>(data_str.size()); |
+ return base::WriteFile(file_path, data_str.c_str(), size) == size; |
+} |
+ |
SourceDir GetToolchainOutputDir(const Settings* settings) { |
return settings->toolchain_output_subdir().AsSourceDir( |
settings->build_settings()); |