Fix log compression storage on windows
authoraggieNick02 <nick@pcpartpicker.com>
Fri, 2 Sep 2022 23:19:43 +0000 (18:19 -0500)
committeraggieNick02 <nick@pcpartpicker.com>
Fri, 2 Sep 2022 23:19:43 +0000 (18:19 -0500)
Set the file open mode to be binary instead of text when dealing with
compressed log files. This fixes log compression storage not working on
windows, and lets the test added in PR
https://github.com/axboe/fio/pull/1458
pass on windows.

Signed-off-by: Nick Neumann <nick@pcpartpicker.com>
iolog.c

diff --git a/iolog.c b/iolog.c
index 41d3e4735036a2a23c7aa157934f5188f39a03b7..aa9c3bb1e4eca43fa0cf1c9794df39656ba80972 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -1218,7 +1218,7 @@ int iolog_file_inflate(const char *file)
        void *buf;
        FILE *f;
 
-       f = fopen(file, "r");
+       f = fopen(file, "rb");
        if (!f) {
                perror("fopen");
                return 1;
@@ -1300,10 +1300,21 @@ void flush_log(struct io_log *log, bool do_append)
        void *buf;
        FILE *f;
 
+       /*
+        * If log_gz_store is true, we are writing a binary file.
+        * Set the mode appropriately (on all platforms) to avoid issues
+        * on windows (line-ending conversions, etc.)
+        */
        if (!do_append)
-               f = fopen(log->filename, "w");
+               if (log->log_gz_store)
+                       f = fopen(log->filename, "wb");
+               else
+                       f = fopen(log->filename, "w");
        else
-               f = fopen(log->filename, "a");
+               if (log->log_gz_store)
+                       f = fopen(log->filename, "ab");
+               else
+                       f = fopen(log->filename, "a");
        if (!f) {
                perror("fopen log");
                return;