Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
a75bacaa
提交
a75bacaa
authored
12月 16, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
The ChangeFileEncryption and Backup tools will now fail if the database is still in use.
上级
2c065a21
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
51 行增加
和
6 行删除
+51
-6
FileLister.java
h2/src/main/org/h2/store/FileLister.java
+29
-3
Backup.java
h2/src/main/org/h2/tools/Backup.java
+3
-0
ChangeFileEncryption.java
h2/src/main/org/h2/tools/ChangeFileEncryption.java
+6
-3
TestTools.java
h2/src/test/org/h2/test/unit/TestTools.java
+13
-0
没有找到文件。
h2/src/main/org/h2/store/FileLister.java
浏览文件 @
a75bacaa
...
...
@@ -8,7 +8,10 @@ package org.h2.store;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.message.Message
;
import
org.h2.message.TraceSystem
;
import
org.h2.util.FileUtils
;
import
org.h2.util.New
;
...
...
@@ -37,14 +40,37 @@ public class FileLister {
return
null
;
}
/**
* Try to lock the database, and then unlock it. If this worked, the
* .lock.db file will be removed.
*
* @param files the database files to check
* @param message the text to include in the error message
* @throws SQLException if it failed
*/
public
static
void
tryUnlockDatabase
(
ArrayList
<
String
>
files
,
String
message
)
throws
SQLException
{
for
(
String
fileName
:
files
)
{
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_LOCK_FILE
))
{
FileLock
lock
=
new
FileLock
(
new
TraceSystem
(
null
,
false
),
fileName
,
Constants
.
LOCK_SLEEP
);
try
{
lock
.
lock
(
FileLock
.
LOCK_FILE
);
lock
.
unlock
();
}
catch
(
SQLException
e
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
CANNOT_CHANGE_SETTING_WHEN_OPEN_1
,
message
);
}
}
}
}
/**
* Get the list of database files.
*
* @param dir the directory (null for the current directory)
* @param db the database name (null for all databases)
* @param all if true, files such as the lock, trace,
hash index,
and lob
* files are included. If false, only data, index
and log files
* are returned
* @param all if true, files such as the lock, trace, and lob
* files are included. If false, only data, index
, log,
* a
nd lob files a
re returned
* @return the list of files
*/
public
static
ArrayList
<
String
>
getDatabaseFiles
(
String
dir
,
String
db
,
boolean
all
)
throws
SQLException
{
...
...
h2/src/main/org/h2/tools/Backup.java
浏览文件 @
a75bacaa
...
...
@@ -24,6 +24,8 @@ import org.h2.util.Tool;
/**
* Creates a backup of a database.
* <br />
* The database must be closed before using this tool.
* @h2.resource
*/
public
class
Backup
extends
Tool
{
...
...
@@ -90,6 +92,7 @@ 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
);
FileLister
.
tryUnlockDatabase
(
list
,
"backup"
);
if
(
list
.
size
()
==
0
)
{
if
(!
quiet
)
{
printNoDatabaseFilesFound
(
directory
,
db
);
...
...
h2/src/main/org/h2/tools/ChangeFileEncryption.java
浏览文件 @
a75bacaa
...
...
@@ -20,6 +20,7 @@ import org.h2.util.Tool;
* Allows changing the database file encryption password or algorithm.
* <br />
* This tool can not be used to change a password of a user.
* The database must be closed before using this tool.
* @h2.resource
*/
public
class
ChangeFileEncryption
extends
Tool
{
...
...
@@ -137,12 +138,14 @@ public class ChangeFileEncryption extends Tool {
change
.
decrypt
=
getFileEncryptionKey
(
decryptPassword
);
change
.
encrypt
=
getFileEncryptionKey
(
encryptPassword
);
// first, test only if the file can be renamed
// (to find errors with locked files early)
ArrayList
<
String
>
files
=
FileLister
.
getDatabaseFiles
(
dir
,
db
,
false
);
ArrayList
<
String
>
files
=
FileLister
.
getDatabaseFiles
(
dir
,
db
,
true
);
FileLister
.
tryUnlockDatabase
(
files
,
"encryption"
);
files
=
FileLister
.
getDatabaseFiles
(
dir
,
db
,
false
);
if
(
files
.
size
()
==
0
&&
!
quiet
)
{
printNoDatabaseFilesFound
(
dir
,
db
);
}
// first, test only if the file can be renamed
// (to find errors with locked files early)
for
(
String
fileName
:
files
)
{
String
temp
=
dir
+
"/temp.db"
;
FileUtils
.
delete
(
temp
);
...
...
h2/src/test/org/h2/test/unit/TestTools.java
浏览文件 @
a75bacaa
...
...
@@ -452,6 +452,12 @@ public class TestTools extends TestBase {
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
assertTrue
(
rs
.
next
());
assertFalse
(
rs
.
next
());
try
{
Backup
.
main
(
"-file"
,
fileName
,
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
conn
.
close
();
DeleteDbFiles
.
main
(
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
);
}
...
...
@@ -473,6 +479,13 @@ public class TestTools extends TestBase {
baseDir
+
"/utils;CIPHER=AES"
,
"sa"
,
"def 123"
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SELECT * FROM TEST"
);
try
{
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-cipher"
,
"AES"
,
"-decrypt"
,
"def"
,
"-quiet"
};
ChangeFileEncryption
.
main
(
args
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
conn
.
close
();
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
};
DeleteDbFiles
.
main
(
args
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论