From 87469c43d7e11ee807a4ead79f0a8593a33ad5c3 Mon Sep 17 00:00:00 2001
From: Yura Sokolov <funny.falcon@gmail.com>
Date: Tue, 18 Apr 2023 17:24:34 +0300
Subject: [PATCH 1/4] lets zerofill files by hand on windows in
 fio_send_file_write

---
 src/utils/file.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/utils/file.c b/src/utils/file.c
index c4ed9c721..0bef52773 100644
--- a/src/utils/file.c
+++ b/src/utils/file.c
@@ -2717,11 +2717,21 @@ fio_send_file_write(FILE* out, send_file_state* st, char *buf, size_t len)
 	if (len == 0)
 		return true;
 
+#ifndef WIN32
 	if (st->read_size > st->write_size &&
 		fseeko(out, st->read_size, SEEK_SET) != 0)
 	{
 		return false;
 	}
+#else
+	while (st->read_size > st->write_size)
+	{
+		size_t wr = st->read_size - st->write_size;
+		wr = Min(wr, sizeof(zerobuf));
+		fwrite(zerobuf, 1, wr, out);
+		st->write_size += wr;
+	}
+#endif
 
 	if (fwrite(buf, 1, len, out) != len)
 	{

From 2538b5d91fa25eb7a2ae25c8b039e260f738eb87 Mon Sep 17 00:00:00 2001
From: Yura Sokolov <funny.falcon@gmail.com>
Date: Tue, 18 Apr 2023 18:25:36 +0300
Subject: [PATCH 2/4] delete "\r" in windows command output.

---
 tests/helpers/ptrack_helpers.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/helpers/ptrack_helpers.py b/tests/helpers/ptrack_helpers.py
index f8044a814..6b665097c 100644
--- a/tests/helpers/ptrack_helpers.py
+++ b/tests/helpers/ptrack_helpers.py
@@ -982,7 +982,8 @@ def run_pb(self, command, asynchronous=False, gdb=False, old_binary=False, retur
                 else:
                     return self.output
         except subprocess.CalledProcessError as e:
-            raise ProbackupException(e.output.decode('utf-8'), self.cmd)
+            raise ProbackupException(e.output.decode('utf-8').replace("\r",""),
+                                     self.cmd)
 
     def run_binary(self, command, asynchronous=False, env=None):
 

From 2640ec6da04321589401b60d5d5f58cf09432512 Mon Sep 17 00:00:00 2001
From: Yura Sokolov <funny.falcon@gmail.com>
Date: Tue, 18 Apr 2023 19:51:58 +0300
Subject: [PATCH 3/4] use _chsize_s on windows to grow file

---
 src/utils/file.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/utils/file.c b/src/utils/file.c
index 0bef52773..47b87f8f9 100644
--- a/src/utils/file.c
+++ b/src/utils/file.c
@@ -2717,21 +2717,19 @@ fio_send_file_write(FILE* out, send_file_state* st, char *buf, size_t len)
 	if (len == 0)
 		return true;
 
-#ifndef WIN32
+#ifdef WIN32
 	if (st->read_size > st->write_size &&
-		fseeko(out, st->read_size, SEEK_SET) != 0)
+		_chsize_s(fileno(out), st->read_size) != 0)
 	{
+		elog(WARNING, "Could not change file size to %lld: %m", st->read_size)
 		return false;
 	}
-#else
-	while (st->read_size > st->write_size)
+#endif
+	if (st->read_size > st->write_size &&
+		fseeko(out, st->read_size, SEEK_SET) != 0)
 	{
-		size_t wr = st->read_size - st->write_size;
-		wr = Min(wr, sizeof(zerobuf));
-		fwrite(zerobuf, 1, wr, out);
-		st->write_size += wr;
+		return false;
 	}
-#endif
 
 	if (fwrite(buf, 1, len, out) != len)
 	{

From b0472a76b5bfc9beeae52bfa05eabe0002d6af3f Mon Sep 17 00:00:00 2001
From: Yura Sokolov <funny.falcon@gmail.com>
Date: Tue, 18 Apr 2023 20:30:46 +0300
Subject: [PATCH 4/4] ... win fix

---
 src/utils/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/utils/file.c b/src/utils/file.c
index 47b87f8f9..e062a2133 100644
--- a/src/utils/file.c
+++ b/src/utils/file.c
@@ -2721,7 +2721,7 @@ fio_send_file_write(FILE* out, send_file_state* st, char *buf, size_t len)
 	if (st->read_size > st->write_size &&
 		_chsize_s(fileno(out), st->read_size) != 0)
 	{
-		elog(WARNING, "Could not change file size to %lld: %m", st->read_size)
+		elog(WARNING, "Could not change file size to %lld: %m", st->read_size);
 		return false;
 	}
 #endif