From d621df28d34d08a3499f47318480c8d3d7b993d8 Mon Sep 17 00:00:00 2001 From: Andrei Tokar Date: Sun, 7 Jul 2024 23:07:09 -0400 Subject: [PATCH] fix backup duplication error --- h2/src/main/org/h2/mvstore/SingleFileStore.java | 4 ++-- h2/src/main/org/h2/util/IOUtils.java | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/h2/src/main/org/h2/mvstore/SingleFileStore.java b/h2/src/main/org/h2/mvstore/SingleFileStore.java index 9794c4faff..c4d42533bd 100644 --- a/h2/src/main/org/h2/mvstore/SingleFileStore.java +++ b/h2/src/main/org/h2/mvstore/SingleFileStore.java @@ -238,11 +238,11 @@ public void backup(ZipOutputStream out) throws IOException { boolean before = mvStore.setReuseSpace(false); try { - IOUtils.copy(in, out); + long copied = IOUtils.copy(in, 0, out); mvStore.executeFilestoreOperation(() -> { try { - IOUtils.copy(in, out); + IOUtils.copy(in, copied, out); } catch (IOException ex) { throw new RuntimeException(ex); } diff --git a/h2/src/main/org/h2/util/IOUtils.java b/h2/src/main/org/h2/util/IOUtils.java index 40bb727bec..128bba0fed 100644 --- a/h2/src/main/org/h2/util/IOUtils.java +++ b/h2/src/main/org/h2/util/IOUtils.java @@ -198,9 +198,9 @@ public static long copy(InputStream in, OutputStream out, long length) * @return the number of bytes copied * @throws IOException on failure */ - public static long copy(FileChannel in, OutputStream out) + public static long copy(FileChannel in, long startAt, OutputStream out) throws IOException { - return copy(in, out, Long.MAX_VALUE); + return copy(in, out, startAt, Long.MAX_VALUE); } /** @@ -213,10 +213,10 @@ public static long copy(FileChannel in, OutputStream out) * @return the number of bytes copied * @throws IOException on failure */ - public static long copy(FileChannel in, OutputStream out, long length) + public static long copy(FileChannel in, OutputStream out, long startAt, long length) throws IOException { try { - long copied = 0; + long copied = startAt; byte[] buffer = new byte[(int) Math.min(length, Constants.IO_BUFFER_SIZE)]; ByteBuffer wrap = ByteBuffer.wrap(buffer); while (length > 0) { @@ -234,7 +234,7 @@ public static long copy(FileChannel in, OutputStream out, long length) wrap.limit((int)length); } } - return copied; + return copied - startAt; } catch (Exception e) { throw DataUtils.convertToIOException(e); }