From cbe61bf87f1539ced0a93af6d7e1b1a8c4e185f0 Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Fri, 7 Jul 2023 14:42:31 +0700 Subject: [PATCH] MDEV-30664 mysqldump output is truncated on Windows Flush stdout on finalizing of mysqldump/mysqlbinlog output to avoid truncation. The same patch has been applied to the mysqltest.cc code with commit 34ff714b0d5456901e979e280399579d3ab3338c Author: Magnus Svensson Date: Fri Nov 14 11:06:56 2008 +0100 WL#4189 Make mysqltest flush log file at close if logfile is stdout but not to mysqldump.c/mysqlbinlog.cc --- client/mysqlbinlog.cc | 9 +++++++-- client/mysqldump.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 8d03e0680b8..8ef11da85d4 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -3224,8 +3224,13 @@ int main(int argc, char** argv) if (tmpdir.list) free_tmpdir(&tmpdir); - if (result_file && result_file != stdout) - my_fclose(result_file, MYF(0)); + if (result_file) + { + if (result_file != stdout) + my_fclose(result_file, MYF(0)); + else + fflush(result_file); + } cleanup(); /* We cannot free DBUG, it is used in global destructors after exit(). */ my_end(my_end_arg | MY_DONT_FREE_DBUG); diff --git a/client/mysqldump.c b/client/mysqldump.c index d0797c2721b..2f1665b4137 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -1794,8 +1794,13 @@ static FILE* open_sql_file_for_table(const char* table, int flags) static void free_resources() { - if (md_result_file && md_result_file != stdout) - my_fclose(md_result_file, MYF(0)); + if (md_result_file) + { + if (md_result_file != stdout) + my_fclose(md_result_file, MYF(0)); + else + fflush(md_result_file); + } if (get_table_name_result) mysql_free_result(get_table_name_result); if (routine_res)