提交 e59f6ba5 authored 作者: Thomas Mueller's avatar Thomas Mueller

The option -baseDir didn't work with symbolic links.

上级 57c231c1
......@@ -100,8 +100,8 @@ public class BackupCommand extends Prepared {
}
private static void backupFile(ZipOutputStream out, String base, String fn) throws IOException {
String f = IOUtils.getAbsolutePath(fn);
base = IOUtils.getAbsolutePath(base);
String f = IOUtils.getCanonicalPath(fn);
base = IOUtils.getCanonicalPath(base);
if (!f.startsWith(base)) {
DbException.throwInternalError(f + " does not start with " + base);
}
......
......@@ -136,7 +136,7 @@ public class ConnectionInfo implements Cloneable {
*/
public void setBaseDir(String dir) {
if (persistent) {
String absDir = IOUtils.unwrap(IOUtils.getAbsolutePath(dir));
String absDir = IOUtils.unwrap(IOUtils.getCanonicalPath(dir));
boolean absolute = IOUtils.isAbsolute(name);
String n;
String prefix = null;
......@@ -147,7 +147,7 @@ public class ConnectionInfo implements Cloneable {
prefix = name.substring(0, name.length() - n.length());
n = dir + SysProperties.FILE_SEPARATOR + n;
}
String normalizedName = IOUtils.unwrap(IOUtils.normalize(n));
String normalizedName = IOUtils.unwrap(IOUtils.getCanonicalPath(n));
if (normalizedName.equals(absDir) || !normalizedName.startsWith(absDir)) {
throw DbException.get(ErrorCode.IO_EXCEPTION_1, normalizedName + " outside " +
absDir);
......@@ -341,7 +341,7 @@ public class ConnectionInfo implements Cloneable {
if (persistent) {
if (nameNormalized == null) {
String suffix = Constants.SUFFIX_PAGE_FILE;
String n = IOUtils.normalize(name + suffix);
String n = IOUtils.getCanonicalPath(name + suffix);
String fileName = IOUtils.getFileName(n);
if (fileName.length() < suffix.length() + 1) {
throw DbException.get(ErrorCode.INVALID_DATABASE_NAME_1, name);
......
......@@ -1302,7 +1302,7 @@ public class Database implements DataHandler {
public String getDatabasePath() {
if (persistent) {
return IOUtils.getAbsolutePath(databaseName);
return IOUtils.getCanonicalPath(databaseName);
}
return null;
}
......
......@@ -198,7 +198,7 @@ public class CipherFactory {
throw DbException.convertToIOException(e);
}
}
String absolutePath = IOUtils.getAbsolutePath(fileName);
String absolutePath = IOUtils.getCanonicalPath(fileName);
System.setProperty(KEYSTORE_KEY, absolutePath);
}
if (p.getProperty(KEYSTORE_PASSWORD_KEY) == null) {
......
......@@ -58,7 +58,7 @@ public class FileLister {
if (dir == null || dir.equals("")) {
return ".";
}
return IOUtils.normalize(dir);
return IOUtils.getCanonicalPath(dir);
}
/**
......@@ -73,7 +73,7 @@ public class FileLister {
*/
public static ArrayList<String> getDatabaseFiles(String dir, String db, boolean all) {
ArrayList<String> files = New.arrayList();
String start = db == null ? null : IOUtils.normalize(dir + "/" + db);
String start = db == null ? null : IOUtils.getCanonicalPath(dir + "/" + db);
String[] list = IOUtils.listFiles(dir);
for (int i = 0; list != null && i < list.length; i++) {
String f = list[i];
......
......@@ -172,7 +172,7 @@ public abstract class FileSystem {
* @param fileName the file name
* @return the normalized file name
*/
public abstract String normalize(String fileName);
public abstract String getCanonicalPath(String fileName);
/**
* Get the parent directory of a file or directory.
......@@ -198,14 +198,6 @@ public abstract class FileSystem {
*/
public abstract boolean isAbsolute(String fileName);
/**
* Get the absolute file name.
*
* @param fileName the file name
* @return the absolute file name
*/
public abstract String getAbsolutePath(String fileName);
/**
* Get the last modified date of a file
*
......
......@@ -243,7 +243,7 @@ public class FileSystemDisk extends FileSystem {
return f.setReadOnly();
}
public String normalize(String fileName) {
public String getCanonicalPath(String fileName) {
fileName = translateFileName(fileName);
File f = new File(fileName);
try {
......@@ -269,12 +269,6 @@ public class FileSystemDisk extends FileSystem {
return file.isAbsolute();
}
public String getAbsolutePath(String fileName) {
fileName = translateFileName(fileName);
File parent = new File(fileName).getAbsoluteFile();
return parent.getAbsolutePath();
}
public long getLastModified(String fileName) {
fileName = translateFileName(fileName);
return new File(fileName).lastModified();
......
......@@ -48,8 +48,8 @@ public class FileSystemMemory extends FileSystem {
}
public void rename(String oldName, String newName) {
oldName = normalize(oldName);
newName = normalize(newName);
oldName = getCanonicalPath(oldName);
newName = getCanonicalPath(newName);
synchronized (MEMORY_FILES) {
FileObjectMemoryData f = getMemoryFile(oldName);
f.setName(newName);
......@@ -69,14 +69,14 @@ public class FileSystemMemory extends FileSystem {
}
public boolean exists(String fileName) {
fileName = normalize(fileName);
fileName = getCanonicalPath(fileName);
synchronized (MEMORY_FILES) {
return MEMORY_FILES.get(fileName) != null;
}
}
public void delete(String fileName) {
fileName = normalize(fileName);
fileName = getCanonicalPath(fileName);
synchronized (MEMORY_FILES) {
MEMORY_FILES.remove(fileName);
}
......@@ -104,7 +104,7 @@ public class FileSystemMemory extends FileSystem {
}
public void deleteRecursive(String fileName, boolean tryOnly) {
fileName = normalize(fileName);
fileName = getCanonicalPath(fileName);
synchronized (MEMORY_FILES) {
Iterator<String> it = MEMORY_FILES.tailMap(fileName).keySet().iterator();
while (it.hasNext()) {
......@@ -126,7 +126,7 @@ public class FileSystemMemory extends FileSystem {
return getMemoryFile(fileName).setReadOnly();
}
public String normalize(String fileName) {
public String getCanonicalPath(String fileName) {
fileName = fileName.replace('\\', '/');
int idx = fileName.indexOf(':') + 1;
if (fileName.length() > idx && fileName.charAt(idx) != '/') {
......@@ -136,7 +136,7 @@ public class FileSystemMemory extends FileSystem {
}
public String getParent(String fileName) {
fileName = normalize(fileName);
fileName = getCanonicalPath(fileName);
int idx = fileName.lastIndexOf('/');
if (idx < 0) {
idx = fileName.indexOf(':') + 1;
......@@ -155,11 +155,6 @@ public class FileSystemMemory extends FileSystem {
return true;
}
public String getAbsolutePath(String fileName) {
// TODO relative files are not supported
return normalize(fileName);
}
public long getLastModified(String fileName) {
return getMemoryFile(fileName).getLastModified();
}
......@@ -188,8 +183,8 @@ public class FileSystemMemory extends FileSystem {
}
public boolean fileStartsWith(String fileName, String prefix) {
fileName = normalize(fileName);
prefix = normalize(prefix);
fileName = getCanonicalPath(fileName);
prefix = getCanonicalPath(prefix);
return fileName.startsWith(prefix);
}
......@@ -215,7 +210,7 @@ public class FileSystemMemory extends FileSystem {
}
private FileObjectMemoryData getMemoryFile(String fileName) {
fileName = normalize(fileName);
fileName = getCanonicalPath(fileName);
synchronized (MEMORY_FILES) {
FileObjectMemoryData m = MEMORY_FILES.get(fileName);
if (m == null) {
......
......@@ -66,10 +66,6 @@ public abstract class FileSystemWrapper extends FileSystem {
return IOUtils.fileStartsWith(unwrap(fileName), unwrap(prefix));
}
public String getAbsolutePath(String fileName) {
return wrap(IOUtils.getAbsolutePath(unwrap(fileName)));
}
public String getFileName(String name) {
return IOUtils.getFileName(unwrap(name));
}
......@@ -106,8 +102,8 @@ public abstract class FileSystemWrapper extends FileSystem {
return array;
}
public String normalize(String fileName) {
return wrap(IOUtils.normalize(unwrap(fileName)));
public String getCanonicalPath(String fileName) {
return wrap(IOUtils.getCanonicalPath(unwrap(fileName)));
}
public InputStream openFileInputStream(String fileName) throws IOException {
......
......@@ -77,10 +77,6 @@ public class FileSystemZip extends FileSystem {
return fileName.startsWith(prefix);
}
public String getAbsolutePath(String fileName) {
return fileName;
}
public String getFileName(String name) {
name = getEntryName(name);
if (name.endsWith("/")) {
......@@ -189,7 +185,7 @@ public class FileSystemZip extends FileSystem {
}
}
public String normalize(String fileName) {
public String getCanonicalPath(String fileName) {
return fileName;
}
......
......@@ -122,7 +122,7 @@ public class Backup extends Tool {
if (!quiet) {
FileLister.tryUnlockDatabase(list, "backup");
}
zipFileName = IOUtils.normalize(zipFileName);
zipFileName = IOUtils.getCanonicalPath(zipFileName);
if (IOUtils.exists(zipFileName)) {
IOUtils.delete(zipFileName);
}
......@@ -138,7 +138,7 @@ public class Backup extends Tool {
}
}
for (String fileName : list) {
String f = IOUtils.getAbsolutePath(fileName);
String f = IOUtils.getCanonicalPath(fileName);
if (!f.startsWith(base)) {
DbException.throwInternalError(f + " does not start with " + base);
}
......
......@@ -587,8 +587,8 @@ public class IOUtils {
* @param fileName the file name
* @return the normalized file name
*/
public static String normalize(String fileName) {
return getFileSystem(fileName).normalize(fileName);
public static String getCanonicalPath(String fileName) {
return getFileSystem(fileName).getCanonicalPath(fileName);
}
/**
......@@ -687,16 +687,6 @@ public class IOUtils {
return getFileSystem(fileName).isAbsolute(fileName);
}
/**
* Get the absolute file name.
*
* @param fileName the file name
* @return the absolute file name
*/
public static String getAbsolutePath(String fileName) {
return getFileSystem(fileName).getAbsolutePath(fileName);
}
/**
* Check if a file starts with a given prefix.
*
......
......@@ -235,7 +235,7 @@ public class ValueLob extends Value {
name = SysProperties.FILE_SEPARATOR + f + Constants.SUFFIX_LOBS_DIRECTORY + name;
objectId /= SysProperties.LOB_FILES_PER_DIRECTORY;
}
name = IOUtils.normalize(path + Constants.SUFFIX_LOBS_DIRECTORY + name);
name = IOUtils.getCanonicalPath(path + Constants.SUFFIX_LOBS_DIRECTORY + name);
return name;
}
......
......@@ -352,7 +352,7 @@ public class FileSystemDatabase extends FileSystem {
}
}
public String normalize(String fileName) {
public String getCanonicalPath(String fileName) {
return fileName;
}
......
......@@ -48,7 +48,7 @@ public class TestFileSystem extends TestBase {
testDatabaseInJar();
// set default part size to 1 << 10
String f = "split:10:" + getBaseDir() + "/fs";
FileSystem.getInstance(f).getAbsolutePath(f);
FileSystem.getInstance(f).getCanonicalPath(f);
testFileSystem(getBaseDir() + "/fs");
testFileSystem(FileSystemMemory.PREFIX);
FileSystemDatabase fs = FileSystemDatabase.register("jdbc:h2:mem:fs");
......@@ -165,7 +165,7 @@ public class TestFileSystem extends TestBase {
private void testUserHome() {
FileSystem fs = FileSystem.getInstance("~/test");
String fileName = fs.getAbsolutePath("~/test");
String fileName = fs.getCanonicalPath("~/test");
String userDir = System.getProperty("user.home");
assertTrue(fileName.startsWith(userDir));
}
......
......@@ -105,11 +105,6 @@ public class DebugFileSystem extends FileSystemWrapper {
return super.fileStartsWith(fileName, prefix);
}
public String getAbsolutePath(String fileName) {
trace(fileName, "getAbsolutePath");
return super.getAbsolutePath(fileName);
}
public String getFileName(String name) {
trace(name, "getFileName");
return super.getFileName(name);
......@@ -155,9 +150,9 @@ public class DebugFileSystem extends FileSystemWrapper {
return super.listFiles(directory);
}
public String normalize(String fileName) {
public String getCanonicalPath(String fileName) {
trace(fileName, "normalize");
return super.normalize(fileName);
return super.getCanonicalPath(fileName);
}
public InputStream openFileInputStream(String fileName) throws IOException {
......
......@@ -328,7 +328,7 @@ public class FtpServer extends Tool implements Service {
if ("-ftpPort".equals(a)) {
port = Integer.decode(args[++i]);
} else if ("-ftpDir".equals(a)) {
root = IOUtils.normalize(args[++i]);
root = IOUtils.getCanonicalPath(args[++i]);
} else if ("-ftpRead".equals(a)) {
readUserName = args[++i];
} else if ("-ftpWrite".equals(a)) {
......@@ -353,7 +353,7 @@ public class FtpServer extends Tool implements Service {
public void start() {
fs = FileSystem.getInstance(root);
root = fs.normalize(root);
root = fs.getCanonicalPath(root);
fs.mkdirs(root);
serverSocket = NetUtils.createServerSocket(port, false);
port = serverSocket.getLocalPort();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论