提交 9e7f4dfe authored 作者: Thomas Mueller's avatar Thomas Mueller

The command line tools now say so if the source directory of an option doesn't exist.

上级 2b6a376e
...@@ -67,6 +67,7 @@ public class BackupCommand extends Prepared { ...@@ -67,6 +67,7 @@ public class BackupCommand extends Prepared {
synchronized (db.getLobSyncObject()) { synchronized (db.getLobSyncObject()) {
String prefix = db.getDatabasePath(); String prefix = db.getDatabasePath();
String dir = IOUtils.getParent(prefix); String dir = IOUtils.getParent(prefix);
dir = FileLister.getDir(dir);
ArrayList<String> fileList = FileLister.getDatabaseFiles(dir, name, true); ArrayList<String> fileList = FileLister.getDatabaseFiles(dir, name, true);
for (String n : fileList) { for (String n : fileList) {
if (n.endsWith(Constants.SUFFIX_LOB_FILE)) { if (n.endsWith(Constants.SUFFIX_LOB_FILE)) {
......
...@@ -62,9 +62,22 @@ public class FileLister { ...@@ -62,9 +62,22 @@ public class FileLister {
} }
/** /**
* Get the list of database files. * Normalize the directory name.
* *
* @param dir the directory (null for the current directory) * @param dir the directory (null for the current directory)
* @return the normalized directory name
*/
public static String getDir(String dir) {
if (dir == null || dir.equals("")) {
return ".";
}
return IOUtils.normalize(dir);
}
/**
* Get the list of database files.
*
* @param dir the directory (must be normalized)
* @param db the database name (null for all databases) * @param db the database name (null for all databases)
* @param all if true, files such as the lock, trace, and lob * @param all if true, files such as the lock, trace, and lob
* files are included. If false, only data, index, log, * files are included. If false, only data, index, log,
...@@ -72,10 +85,6 @@ public class FileLister { ...@@ -72,10 +85,6 @@ public class FileLister {
* @return the list of files * @return the list of files
*/ */
public static ArrayList<String> getDatabaseFiles(String dir, String db, boolean all) { public static ArrayList<String> getDatabaseFiles(String dir, String db, boolean all) {
if (dir == null || dir.equals("")) {
dir = ".";
}
dir = IOUtils.normalize(dir);
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.normalize(dir + "/" + db);
String[] list = IOUtils.listFiles(dir); String[] list = IOUtils.listFiles(dir);
......
...@@ -105,15 +105,15 @@ public class Backup extends Tool { ...@@ -105,15 +105,15 @@ public class Backup extends Tool {
private void process(String zipFileName, String directory, String db, boolean quiet) throws SQLException { private void process(String zipFileName, String directory, String db, boolean quiet) throws SQLException {
ArrayList<String> list = FileLister.getDatabaseFiles(directory, db, true); ArrayList<String> list = FileLister.getDatabaseFiles(directory, db, true);
if (!quiet) {
FileLister.tryUnlockDatabase(list, "backup");
}
if (list.size() == 0) { if (list.size() == 0) {
if (!quiet) { if (!quiet) {
printNoDatabaseFilesFound(directory, db); printNoDatabaseFilesFound(directory, db);
} }
return; return;
} }
if (!quiet) {
FileLister.tryUnlockDatabase(list, "backup");
}
zipFileName = IOUtils.normalize(zipFileName); zipFileName = IOUtils.normalize(zipFileName);
if (IOUtils.exists(zipFileName)) { if (IOUtils.exists(zipFileName)) {
IOUtils.delete(zipFileName); IOUtils.delete(zipFileName);
......
...@@ -131,6 +131,7 @@ public class ChangeFileEncryption extends Tool { ...@@ -131,6 +131,7 @@ public class ChangeFileEncryption extends Tool {
} }
private void process(String dir, String db, String cipher, char[] decryptPassword, char[] encryptPassword, boolean quiet) throws SQLException { private void process(String dir, String db, String cipher, char[] decryptPassword, char[] encryptPassword, boolean quiet) throws SQLException {
dir = FileLister.getDir(dir);
ChangeFileEncryption change = new ChangeFileEncryption(); ChangeFileEncryption change = new ChangeFileEncryption();
if (encryptPassword != null) { if (encryptPassword != null) {
for (char c : encryptPassword) { for (char c : encryptPassword) {
......
...@@ -85,11 +85,11 @@ public class DeleteDbFiles extends Tool { ...@@ -85,11 +85,11 @@ public class DeleteDbFiles extends Tool {
* @throws SQLException * @throws SQLException
*/ */
private void process(String dir, String db, boolean quiet) throws SQLException { private void process(String dir, String db, boolean quiet) throws SQLException {
DeleteDbFiles delete = new DeleteDbFiles();
ArrayList<String> files = FileLister.getDatabaseFiles(dir, db, true); ArrayList<String> files = FileLister.getDatabaseFiles(dir, db, true);
if (files.size() == 0 && !quiet) { if (files.size() == 0 && !quiet) {
printNoDatabaseFilesFound(dir, db); printNoDatabaseFilesFound(dir, db);
} }
DeleteDbFiles delete = new DeleteDbFiles();
for (String fileName : files) { for (String fileName : files) {
delete.process(fileName, quiet); delete.process(fileName, quiet);
if (!quiet) { if (!quiet) {
......
...@@ -11,6 +11,7 @@ import java.io.IOException; ...@@ -11,6 +11,7 @@ import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Properties; import java.util.Properties;
import org.h2.store.FileLister;
/** /**
* Command line tools implement the tool interface so that they can be used in * Command line tools implement the tool interface so that they can be used in
...@@ -59,13 +60,18 @@ public abstract class Tool { ...@@ -59,13 +60,18 @@ public abstract class Tool {
* @param db the database name or null * @param db the database name or null
*/ */
protected void printNoDatabaseFilesFound(String dir, String db) { protected void printNoDatabaseFilesFound(String dir, String db) {
StringBuilder buff = new StringBuilder("No database files have been found"); StringBuilder buff;
if (dir != null) { dir = FileLister.getDir(dir);
if (!IOUtils.isDirectory(dir)) {
buff = new StringBuilder("Directory not found: ");
buff.append(dir);
} else {
buff = new StringBuilder("No database files have been found");
buff.append(" in directory ").append(dir); buff.append(" in directory ").append(dir);
}
if (db != null) { if (db != null) {
buff.append(" for the database ").append(db); buff.append(" for the database ").append(db);
} }
}
out.println(buff.toString()); out.println(buff.toString());
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论