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