diff options
| author | levlam <levlam@telegram.org> | 2023-06-26 15:08:36 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2023-06-26 15:08:36 +0300 |
| commit | 496dc3284ecd37e673f1f4563bca9b3bb3904195 (patch) | |
| tree | 7e12231c340ec877f18e3aed47a67aa5c665d211 /tdtl | |
| parent | c8824c15fda7cbe8397e1016e438963b87ca07d0 (diff) | |
Always compare file content before replacing it.
Diffstat (limited to 'tdtl')
| -rw-r--r-- | tdtl/td/tl/tl_file_utils.cpp | 13 | ||||
| -rw-r--r-- | tdtl/td/tl/tl_file_utils.h | 2 | ||||
| -rw-r--r-- | tdtl/td/tl/tl_generate.cpp | 13 |
3 files changed, 14 insertions, 14 deletions
diff --git a/tdtl/td/tl/tl_file_utils.cpp b/tdtl/td/tl/tl_file_utils.cpp index 91c859d03..a78f8d29f 100644 --- a/tdtl/td/tl/tl_file_utils.cpp +++ b/tdtl/td/tl/tl_file_utils.cpp @@ -44,7 +44,18 @@ std::string get_file_contents(const std::string &file_name) { return result; } -bool put_file_contents(const std::string &file_name, const std::string &contents) { +bool put_file_contents(const std::string &file_name, const std::string &contents, bool compare_documentation) { + std::string old_file_contents = get_file_contents(file_name); + if (!compare_documentation) { + old_file_contents = remove_documentation(old_file_contents); + } + + if (old_file_contents == contents) { + return true; + } + + std::fprintf(stderr, "Write file %s\n", file_name.c_str()); + FILE *f = std::fopen(file_name.c_str(), "wb"); if (f == NULL) { std::fprintf(stderr, "Can't open file \"%s\"\n", file_name.c_str()); diff --git a/tdtl/td/tl/tl_file_utils.h b/tdtl/td/tl/tl_file_utils.h index 6d4cc7132..420d26948 100644 --- a/tdtl/td/tl/tl_file_utils.h +++ b/tdtl/td/tl/tl_file_utils.h @@ -13,7 +13,7 @@ namespace tl { std::string get_file_contents(const std::string &file_name); -bool put_file_contents(const std::string &file_name, const std::string &contents); +bool put_file_contents(const std::string &file_name, const std::string &contents, bool compare_documentation); std::string remove_documentation(const std::string &str); diff --git a/tdtl/td/tl/tl_generate.cpp b/tdtl/td/tl/tl_generate.cpp index 62345df79..5222dd318 100644 --- a/tdtl/td/tl/tl_generate.cpp +++ b/tdtl/td/tl/tl_generate.cpp @@ -883,18 +883,7 @@ tl_config read_tl_config_from_file(const std::string &file_name) { bool write_tl_to_file(const tl_config &config, const std::string &file_name, const TL_writer &w) { tl_string_outputer out; write_tl(config, out, w); - - std::string old_file_contents = get_file_contents(file_name); - if (!w.is_documentation_generated()) { - old_file_contents = remove_documentation(old_file_contents); - } - - if (old_file_contents != out.get_result()) { - std::fprintf(stderr, "Write tl to file %s\n", file_name.c_str()); - return put_file_contents(file_name, out.get_result()); - } - - return true; + return put_file_contents(file_name, out.get_result(), w.is_documentation_generated()); } } // namespace tl |
