Skip to content

Commit

Permalink
fix backup duplication error
Browse files Browse the repository at this point in the history
  • Loading branch information
andreitokar committed Jul 8, 2024
1 parent 0bd1376 commit d621df2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions h2/src/main/org/h2/mvstore/SingleFileStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions h2/src/main/org/h2/util/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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) {
Expand All @@ -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);
}
Expand Down

0 comments on commit d621df2

Please sign in to comment.