提交 83a21918 authored 作者: Thomas Mueller's avatar Thomas Mueller

encrypted script files of earlier versions could not be processed.

上级 011a7674
......@@ -304,6 +304,12 @@ public class Constants {
*/
public static final String MAGIC_FILE_HEADER = "-- H2 0.5/B -- ".substring(0, FILE_BLOCK_SIZE - 1) + "\n";
/**
* If old text file headers should be supported. This setting can be removed
* in future versions (required for compatibility with version 1.1.103).
*/
public static final boolean MAGIC_FILE_HEADER_SUPPORT_TEXT = true;
/**
* The name of the in-memory management database used by the TCP server
* to keep the active sessions.
......@@ -455,11 +461,6 @@ public class Constants {
*/
public static final String SUFFIX_TRACE_FILE = ".trace.db";
/**
* The file name suffix of the signal file that starts trace output.
*/
public static final String SUFFIX_TRACE_START_FILE = ".start";
/**
* The table name suffix used to create internal temporary tables.
*/
......
......@@ -58,6 +58,7 @@ public class FileStore {
private boolean synchronousMode;
private String mode;
private TempFileDeleter tempFileDeleter;
private boolean textMode;
/**
* Create a new file using the given settings.
......@@ -195,6 +196,12 @@ public class FileStore {
seek(0);
byte[] buff = new byte[len];
readFullyDirect(buff, 0, len);
if (Constants.MAGIC_FILE_HEADER_SUPPORT_TEXT) {
if (buff[10] == 'T') {
buff[10] = 'B';
textMode = true;
}
}
if (ByteUtils.compareNotNull(buff, magic) != 0) {
throw Message.getSQLException(ErrorCode.FILE_VERSION_ERROR_1, name);
}
......@@ -203,6 +210,9 @@ public class FileStore {
initKey(salt);
// read (maybe) encrypted
readFully(buff, 0, Constants.FILE_BLOCK_SIZE);
if (textMode) {
buff[10] = 'B';
}
if (ByteUtils.compareNotNull(buff, magic) != 0) {
throw Message.getSQLException(ErrorCode.FILE_ENCRYPTION_ERROR_1, name);
}
......@@ -510,4 +520,13 @@ public class FileStore {
}
}
/**
* Check if the file store is in text mode.
*
* @return true if it is
*/
public boolean isTextMode() {
return textMode;
}
}
......@@ -98,7 +98,7 @@ public class FileStoreInputStream extends InputStream {
throw Message.convertToIOException(e);
}
page.reset();
remainingInBuffer = page.readInt();
remainingInBuffer = readInt();
if (remainingInBuffer < 0) {
close();
return;
......@@ -107,19 +107,19 @@ public class FileStoreInputStream extends InputStream {
// get the length to read
if (compress != null) {
page.checkCapacity(DataPage.LENGTH_INT);
page.readInt();
readInt();
}
page.setPos(page.length() + remainingInBuffer);
page.fillAligned();
int len = page.length() - Constants.FILE_BLOCK_SIZE;
page.reset();
page.readInt();
readInt();
try {
store.readFully(page.getBytes(), Constants.FILE_BLOCK_SIZE, len);
page.reset();
page.readInt();
readInt();
if (compress != null) {
int uncompressed = page.readInt();
int uncompressed = readInt();
byte[] buff = ByteUtils.newBytes(remainingInBuffer);
page.read(buff, 0, remainingInBuffer);
page.reset();
......@@ -167,4 +167,14 @@ public class FileStoreInputStream extends InputStream {
return i;
}
public int readInt() {
if (store.isTextMode()) {
byte[] buff = new byte[8];
page.read(buff, 0, 8);
String s = new String(buff);
return Integer.parseInt(s, 16);
}
return page.readInt();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论