提交 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 {
synchronized (db.getLobSyncObject()) {
String prefix = db.getDatabasePath();
String dir = IOUtils.getParent(prefix);
dir = FileLister.getDir(dir);
ArrayList<String> fileList = FileLister.getDatabaseFiles(dir, name, true);
for (String n : fileList) {
if (n.endsWith(Constants.SUFFIX_LOB_FILE)) {
......
......@@ -62,20 +62,29 @@ public class FileLister {
}
/**
* Get the list of database files.
* Normalize the directory name.
*
* @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 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,
* and lob files are returned
* @return the list of files
*/
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();
String start = db == null ? null : IOUtils.normalize(dir + "/" + db);
String[] list = IOUtils.listFiles(dir);
......
......@@ -105,15 +105,15 @@ public class Backup extends Tool {
private void process(String zipFileName, String directory, String db, boolean quiet) throws SQLException {
ArrayList<String> list = FileLister.getDatabaseFiles(directory, db, true);
if (!quiet) {
FileLister.tryUnlockDatabase(list, "backup");
}
if (list.size() == 0) {
if (!quiet) {
printNoDatabaseFilesFound(directory, db);
}
return;
}
if (!quiet) {
FileLister.tryUnlockDatabase(list, "backup");
}
zipFileName = IOUtils.normalize(zipFileName);
if (IOUtils.exists(zipFileName)) {
IOUtils.delete(zipFileName);
......
......@@ -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 {
dir = FileLister.getDir(dir);
ChangeFileEncryption change = new ChangeFileEncryption();
if (encryptPassword != null) {
for (char c : encryptPassword) {
......
......@@ -85,11 +85,11 @@ public class DeleteDbFiles extends Tool {
* @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);
if (files.size() == 0 && !quiet) {
printNoDatabaseFilesFound(dir, db);
}
DeleteDbFiles delete = new DeleteDbFiles();
for (String fileName : files) {
delete.process(fileName, quiet);
if (!quiet) {
......
......@@ -11,6 +11,7 @@ import java.io.IOException;
import java.io.PrintStream;
import java.sql.SQLException;
import java.util.Properties;
import org.h2.store.FileLister;
/**
* Command line tools implement the tool interface so that they can be used in
......@@ -59,12 +60,17 @@ public abstract class Tool {
* @param db the database name or null
*/
protected void printNoDatabaseFilesFound(String dir, String db) {
StringBuilder buff = new StringBuilder("No database files have been found");
if (dir != null) {
StringBuilder buff;
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);
}
if (db != null) {
buff.append(" for the database ").append(db);
if (db != null) {
buff.append(" for the database ").append(db);
}
}
out.println(buff.toString());
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论