提交 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 { ...@@ -163,6 +163,9 @@ public class ConnectionInfo implements Cloneable {
boolean absolute = FileUtils.isAbsolute(name); boolean absolute = FileUtils.isAbsolute(name);
String n; String n;
String prefix = null; String prefix = null;
if (dir.endsWith(SysProperties.FILE_SEPARATOR)) {
dir = dir.substring(0, dir.length() - 1);
}
if (absolute) { if (absolute) {
n = name; n = name;
} else { } else {
......
...@@ -68,7 +68,12 @@ public class FilePathZip extends FilePath { ...@@ -68,7 +68,12 @@ public class FilePathZip extends FilePath {
} }
public boolean isAbsolute() { 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() { public boolean isDirectory() {
......
...@@ -9,14 +9,18 @@ package org.h2.test.db; ...@@ -9,14 +9,18 @@ package org.h2.test.db;
import java.io.File; import java.io.File;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.dev.fs.FilePathZip2;
import org.h2.store.FileLister; import org.h2.store.FileLister;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.tools.Backup;
import org.h2.tools.Server;
/** /**
* Test for the read-only database feature. * Test for the read-only database feature.
...@@ -36,6 +40,7 @@ public class TestReadOnly extends TestBase { ...@@ -36,6 +40,7 @@ public class TestReadOnly extends TestBase {
if (config.memory) { if (config.memory) {
return; return;
} }
testReadOnlyInZip();
testReadOnlyTempTableResult(); testReadOnlyTempTableResult();
testReadOnlyConnect(); testReadOnlyConnect();
testReadOnlyDbCreate(); testReadOnlyDbCreate();
...@@ -46,6 +51,38 @@ public class TestReadOnly extends TestBase { ...@@ -46,6 +51,38 @@ public class TestReadOnly extends TestBase {
deleteDb("readonly"); 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 { private void testReadOnlyTempTableResult() throws SQLException {
deleteDb("readonly"); deleteDb("readonly");
Connection conn = getConnection("readonly"); Connection conn = getConnection("readonly");
......
...@@ -199,7 +199,7 @@ public class TestFileSystem extends TestBase { ...@@ -199,7 +199,7 @@ public class TestFileSystem extends TestBase {
deleteDb("fsJar"); deleteDb("fsJar");
for (String f : FileUtils.newDirectoryStream("zip:" + getBaseDir() + "/fsJar.zip")) { for (String f : FileUtils.newDirectoryStream("zip:" + getBaseDir() + "/fsJar.zip")) {
assertTrue(FileUtils.isAbsolute(f)); assertFalse(FileUtils.isAbsolute(f));
assertTrue(!FileUtils.isDirectory(f)); assertTrue(!FileUtils.isDirectory(f));
assertTrue(FileUtils.size(f) > 0); assertTrue(FileUtils.size(f) > 0);
assertTrue(f.endsWith(FileUtils.getName(f))); assertTrue(f.endsWith(FileUtils.getName(f)));
......
...@@ -96,10 +96,6 @@ public class FilePathZip2 extends FilePath { ...@@ -96,10 +96,6 @@ public class FilePathZip2 extends FilePath {
} }
} }
// public boolean fileStartsWith(String fileName, String prefix) {
// return fileName.startsWith(prefix);
// }
public long lastModified() { public long lastModified() {
return 0; return 0;
} }
...@@ -110,7 +106,12 @@ public class FilePathZip2 extends FilePath { ...@@ -110,7 +106,12 @@ public class FilePathZip2 extends FilePath {
} }
public boolean isAbsolute() { 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() { public boolean isDirectory() {
...@@ -258,17 +259,6 @@ public class FilePathZip2 extends FilePath { ...@@ -258,17 +259,6 @@ public class FilePathZip2 extends FilePath {
throw DbException.getUnsupportedException("write"); 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() { private String getEntryName() {
int idx = name.indexOf('!'); int idx = name.indexOf('!');
String fileName; String fileName;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论