提交 7cce979b authored 作者: Thomas Mueller's avatar Thomas Mueller

Read-only databases in a zip file did not work when using the -baseDir option.

上级 3b138227
......@@ -163,6 +163,9 @@ public class ConnectionInfo implements Cloneable {
boolean absolute = FileUtils.isAbsolute(name);
String n;
String prefix = null;
if (dir.endsWith(SysProperties.FILE_SEPARATOR)) {
dir = dir.substring(0, dir.length() - 1);
}
if (absolute) {
n = name;
} else {
......
......@@ -68,7 +68,12 @@ public class FilePathZip extends FilePath {
}
public boolean isAbsolute() {
return true;
String fileName = translateFileName(name);
return FilePath.get(fileName).isAbsolute();
}
public FilePath unwrap() {
return FilePath.get(name.substring(getScheme().length() + 1));
}
public boolean isDirectory() {
......
......@@ -9,14 +9,18 @@ package org.h2.test.db;
import java.io.File;
import java.io.RandomAccessFile;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import org.h2.constant.ErrorCode;
import org.h2.dev.fs.FilePathZip2;
import org.h2.store.FileLister;
import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase;
import org.h2.tools.Backup;
import org.h2.tools.Server;
/**
* Test for the read-only database feature.
......@@ -36,6 +40,7 @@ public class TestReadOnly extends TestBase {
if (config.memory) {
return;
}
testReadOnlyInZip();
testReadOnlyTempTableResult();
testReadOnlyConnect();
testReadOnlyDbCreate();
......@@ -46,6 +51,38 @@ public class TestReadOnly extends TestBase {
deleteDb("readonly");
}
private void testReadOnlyInZip() throws SQLException {
deleteDb("readonly");
String dir = getBaseDir();
Connection conn = getConnection("readonly");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT) AS SELECT X FROM SYSTEM_RANGE(1, 20)");
conn.close();
Backup.execute(dir + "/readonly.zip", dir, "readonly", true);
conn = DriverManager.getConnection(
"jdbc:h2:zip:"+dir+"/readonly.zip!/readonly", getUser(), getPassword());
conn.createStatement().execute("select * from test where id=1");
conn.close();
Server server = Server.createTcpServer("-tcpPort", "9081", "-baseDir", dir);
server.start();
try {
conn = DriverManager.getConnection(
"jdbc:h2:tcp://localhost:9081/zip:readonly.zip!/readonly",
getUser(), getPassword());
conn.createStatement().execute("select * from test where id=1");
conn.close();
FilePathZip2.register();
conn = DriverManager.getConnection(
"jdbc:h2:tcp://localhost:9081/zip2:readonly.zip!/readonly",
getUser(), getPassword());
conn.createStatement().execute("select * from test where id=1");
conn.close();
} finally {
server.stop();
}
FileUtils.deleteRecursive(dir, false);
}
private void testReadOnlyTempTableResult() throws SQLException {
deleteDb("readonly");
Connection conn = getConnection("readonly");
......
......@@ -199,7 +199,7 @@ public class TestFileSystem extends TestBase {
deleteDb("fsJar");
for (String f : FileUtils.newDirectoryStream("zip:" + getBaseDir() + "/fsJar.zip")) {
assertTrue(FileUtils.isAbsolute(f));
assertFalse(FileUtils.isAbsolute(f));
assertTrue(!FileUtils.isDirectory(f));
assertTrue(FileUtils.size(f) > 0);
assertTrue(f.endsWith(FileUtils.getName(f)));
......
......@@ -96,10 +96,6 @@ public class FilePathZip2 extends FilePath {
}
}
// public boolean fileStartsWith(String fileName, String prefix) {
// return fileName.startsWith(prefix);
// }
public long lastModified() {
return 0;
}
......@@ -110,7 +106,12 @@ public class FilePathZip2 extends FilePath {
}
public boolean isAbsolute() {
return true;
String fileName = translateFileName(name);
return FilePath.get(fileName).isAbsolute();
}
public FilePath unwrap() {
return FilePath.get(name.substring(getScheme().length() + 1));
}
public boolean isDirectory() {
......@@ -258,17 +259,6 @@ public class FilePathZip2 extends FilePath {
throw DbException.getUnsupportedException("write");
}
// public String unwrap(String fileName) {
// if (fileName.startsWith(PREFIX)) {
// fileName = fileName.substring(PREFIX.length());
// }
// int idx = fileName.indexOf('!');
// if (idx >= 0) {
// fileName = fileName.substring(0, idx);
// }
// return FileSystemDisk.expandUserHomeDirectory(fileName);
// }
private String getEntryName() {
int idx = name.indexOf('!');
String fileName;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论