Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
6992e031
提交
6992e031
authored
9月 12, 2011
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improved compatibility with the Java 7 FileSystem abstraction.
上级
19ae5c8b
隐藏空白字符变更
内嵌
并排
正在显示
24 个修改的文件
包含
107 行增加
和
169 行删除
+107
-169
changelog.html
h2/src/docsrc/html/changelog.html
+1
-1
TraceSystem.java
h2/src/main/org/h2/message/TraceSystem.java
+1
-1
FileLock.java
h2/src/main/org/h2/store/FileLock.java
+4
-3
FileStore.java
h2/src/main/org/h2/store/FileStore.java
+2
-1
FileSystem.java
h2/src/main/org/h2/store/fs/FileSystem.java
+3
-11
FileSystemDisk.java
h2/src/main/org/h2/store/fs/FileSystemDisk.java
+10
-28
FileSystemMemory.java
h2/src/main/org/h2/store/fs/FileSystemMemory.java
+4
-17
FileSystemWrapper.java
h2/src/main/org/h2/store/fs/FileSystemWrapper.java
+2
-6
FileSystemZip.java
h2/src/main/org/h2/store/fs/FileSystemZip.java
+1
-5
Recorder.java
h2/src/main/org/h2/store/fs/Recorder.java
+4
-9
RecordingFileSystem.java
h2/src/main/org/h2/store/fs/RecordingFileSystem.java
+3
-8
IOUtils.java
h2/src/main/org/h2/util/IOUtils.java
+38
-14
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+5
-5
TestFullText.java
h2/src/test/org/h2/test/db/TestFullText.java
+2
-3
TestRecoverKillLoop.java
h2/src/test/org/h2/test/poweroff/TestRecoverKillLoop.java
+2
-2
TestInit.java
h2/src/test/org/h2/test/server/TestInit.java
+1
-1
FileSystemDatabase.java
h2/src/test/org/h2/test/unit/FileSystemDatabase.java
+10
-32
TestFileSystem.java
h2/src/test/org/h2/test/unit/TestFileSystem.java
+4
-4
TestStreams.java
h2/src/test/org/h2/test/unit/TestStreams.java
+1
-1
DebugFileSystem.java
h2/src/test/org/h2/test/utils/DebugFileSystem.java
+3
-8
FileShell.java
h2/src/tools/org/h2/dev/fs/FileShell.java
+2
-2
FileSystemZip2.java
h2/src/tools/org/h2/dev/fs/FileSystemZip2.java
+1
-5
FtpControl.java
h2/src/tools/org/h2/dev/ftp/server/FtpControl.java
+2
-1
FtpServer.java
h2/src/tools/org/h2/dev/ftp/server/FtpServer.java
+1
-1
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
6992e031
...
...
@@ -18,7 +18,7 @@ Change Log
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
-
<ul><li>
Improved compatibility with the Java 7 FileSystem abstraction.
</li></ul>
<h2>
Version 1.3.160 (2011-09-11)
</h2>
...
...
h2/src/main/org/h2/message/TraceSystem.java
浏览文件 @
6992e031
...
...
@@ -296,7 +296,7 @@ public class TraceSystem implements TraceWriter {
private
boolean
openWriter
()
{
if
(
printWriter
==
null
)
{
try
{
IOUtils
.
createDir
s
(
fileName
);
IOUtils
.
createDir
ectories
(
IOUtils
.
getParent
(
fileName
)
);
if
(
IOUtils
.
exists
(
fileName
)
&&
IOUtils
.
isReadOnly
(
fileName
))
{
// read only database: don't log error if the trace file
// can't be opened
...
...
h2/src/main/org/h2/store/FileLock.java
浏览文件 @
6992e031
...
...
@@ -22,6 +22,7 @@ import org.h2.message.DbException;
import
org.h2.message.Trace
;
import
org.h2.message.TraceSystem
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.util.IOUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.NetUtils
;
import
org.h2.util.SortedProperties
;
...
...
@@ -302,7 +303,7 @@ public class FileLock implements Runnable {
private
void
lockSerialized
()
{
method
=
SERIALIZED
;
fs
.
createDirs
(
fileName
);
IOUtils
.
createDirectories
(
fs
.
getParent
(
fileName
)
);
if
(
fs
.
createNewFile
(
fileName
))
{
properties
=
new
SortedProperties
();
properties
.
setProperty
(
"method"
,
String
.
valueOf
(
method
));
...
...
@@ -325,7 +326,7 @@ public class FileLock implements Runnable {
properties
=
new
SortedProperties
();
properties
.
setProperty
(
"method"
,
String
.
valueOf
(
method
));
setUniqueId
();
fs
.
createDirs
(
fileName
);
IOUtils
.
createDirectories
(
fs
.
getParent
(
fileName
)
);
if
(!
fs
.
createNewFile
(
fileName
))
{
waitUntilOld
();
String
m2
=
load
().
getProperty
(
"method"
,
FILE
);
...
...
@@ -362,7 +363,7 @@ public class FileLock implements Runnable {
// if this returns 127.0.0.1,
// the computer is probably not networked
ipAddress
=
NetUtils
.
getLocalAddress
();
fs
.
createDirs
(
fileName
);
IOUtils
.
createDirectories
(
fs
.
getParent
(
fileName
)
);
if
(!
fs
.
createNewFile
(
fileName
))
{
waitUntilOld
();
long
read
=
fs
.
getLastModified
(
fileName
);
...
...
h2/src/main/org/h2/store/FileStore.java
浏览文件 @
6992e031
...
...
@@ -15,6 +15,7 @@ import org.h2.message.DbException;
import
org.h2.security.SecureFileStore
;
import
org.h2.store.fs.FileObject
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.util.IOUtils
;
import
org.h2.util.TempFileDeleter
;
import
org.h2.util.Utils
;
...
...
@@ -83,7 +84,7 @@ public class FileStore {
mode
=
"r"
;
this
.
mode
=
mode
;
}
else
{
fs
.
createDirs
(
name
);
IOUtils
.
createDirectories
(
fs
.
getParent
(
name
)
);
}
file
=
fs
.
openFileObject
(
name
,
mode
);
if
(
mode
.
length
()
>
2
)
{
...
...
h2/src/main/org/h2/store/fs/FileSystem.java
浏览文件 @
6992e031
...
...
@@ -150,14 +150,6 @@ public abstract class FileSystem {
*/
public
abstract
String
[]
listFiles
(
String
directory
);
/**
* Delete a directory or file and all subdirectories and files.
*
* @param directory the directory
* @param tryOnly whether errors should be ignored
*/
public
abstract
void
deleteRecursive
(
String
directory
,
boolean
tryOnly
);
/**
* Check if a file is read-only.
*
...
...
@@ -215,11 +207,11 @@ public abstract class FileSystem {
public
abstract
boolean
canWrite
(
String
fileName
);
/**
* Create a
ll required directories that are required for this file
.
* Create a
directory (all required parent directories already exist)
.
*
* @param
fileName the file name (not directory name)
* @param
directoryName the directory name
*/
public
abstract
void
createDir
s
(
String
file
Name
);
public
abstract
void
createDir
ectory
(
String
directory
Name
);
/**
* Get the file name (without directory part).
...
...
h2/src/main/org/h2/store/fs/FileSystemDisk.java
浏览文件 @
6992e031
...
...
@@ -215,23 +215,6 @@ public class FileSystemDisk extends FileSystem {
}
}
public
void
deleteRecursive
(
String
fileName
,
boolean
tryOnly
)
{
fileName
=
translateFileName
(
fileName
);
if
(
IOUtils
.
isDirectory
(
fileName
))
{
String
[]
list
=
listFiles
(
fileName
);
if
(
list
!=
null
)
{
for
(
String
l
:
list
)
{
deleteRecursive
(
l
,
tryOnly
);
}
}
}
if
(
tryOnly
)
{
tryDelete
(
fileName
);
}
else
{
delete
(
fileName
);
}
}
public
boolean
isReadOnly
(
String
fileName
)
{
fileName
=
translateFileName
(
fileName
);
File
f
=
new
File
(
fileName
);
...
...
@@ -310,22 +293,18 @@ public class FileSystemDisk extends FileSystem {
}
}
public
void
createDir
s
(
String
file
Name
)
{
fileName
=
translateFileName
(
file
Name
);
File
f
=
new
File
(
file
Name
);
public
void
createDir
ectory
(
String
directory
Name
)
{
directoryName
=
translateFileName
(
directory
Name
);
File
f
=
new
File
(
directory
Name
);
if
(!
f
.
exists
())
{
String
parent
=
f
.
getParent
();
if
(
parent
==
null
)
{
return
;
}
File
dir
=
new
File
(
parent
);
File
dir
=
new
File
(
directoryName
);
for
(
int
i
=
0
;
i
<
SysProperties
.
MAX_FILE_RETRY
;
i
++)
{
if
((
dir
.
exists
()
&&
dir
.
isDirectory
())
||
dir
.
mkdir
s
())
{
if
((
dir
.
exists
()
&&
dir
.
isDirectory
())
||
dir
.
mkdir
())
{
return
;
}
wait
(
i
);
}
throw
DbException
.
get
(
ErrorCode
.
FILE_CREATION_FAILED_1
,
parent
);
throw
DbException
.
get
(
ErrorCode
.
FILE_CREATION_FAILED_1
,
directoryName
);
}
}
...
...
@@ -348,7 +327,10 @@ public class FileSystemDisk extends FileSystem {
fileName
=
translateFileName
(
fileName
);
try
{
File
file
=
new
File
(
fileName
);
createDirs
(
file
.
getAbsolutePath
());
File
parent
=
file
.
getParentFile
();
if
(
parent
!=
null
)
{
IOUtils
.
createDirectories
(
parent
.
getAbsolutePath
());
}
FileOutputStream
out
=
new
FileOutputStream
(
fileName
,
append
);
IOUtils
.
trace
(
"openFileOutputStream"
,
fileName
,
out
);
return
out
;
...
...
h2/src/main/org/h2/store/fs/FileSystemMemory.java
浏览文件 @
6992e031
...
...
@@ -10,7 +10,6 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.TreeMap
;
import
org.h2.message.DbException
;
import
org.h2.util.New
;
...
...
@@ -69,6 +68,9 @@ public class FileSystemMemory extends FileSystem {
public
boolean
exists
(
String
fileName
)
{
fileName
=
getCanonicalPath
(
fileName
);
if
(
fileName
.
equals
(
PREFIX
)
||
fileName
.
equals
(
PREFIX_LZF
))
{
return
true
;
}
synchronized
(
MEMORY_FILES
)
{
return
MEMORY_FILES
.
get
(
fileName
)
!=
null
;
}
...
...
@@ -103,21 +105,6 @@ public class FileSystemMemory extends FileSystem {
}
}
public
void
deleteRecursive
(
String
fileName
,
boolean
tryOnly
)
{
fileName
=
getCanonicalPath
(
fileName
);
synchronized
(
MEMORY_FILES
)
{
Iterator
<
String
>
it
=
MEMORY_FILES
.
tailMap
(
fileName
).
keySet
().
iterator
();
while
(
it
.
hasNext
())
{
String
name
=
it
.
next
();
if
(
name
.
startsWith
(
fileName
))
{
it
.
remove
();
}
else
{
break
;
}
}
}
}
public
boolean
isReadOnly
(
String
fileName
)
{
return
!
getMemoryFile
(
fileName
).
canWrite
();
}
...
...
@@ -163,7 +150,7 @@ public class FileSystemMemory extends FileSystem {
return
true
;
}
public
void
createDir
s
(
String
file
Name
)
{
public
void
createDir
ectory
(
String
directory
Name
)
{
// TODO directories are not really supported
}
...
...
h2/src/main/org/h2/store/fs/FileSystemWrapper.java
浏览文件 @
6992e031
...
...
@@ -33,8 +33,8 @@ public abstract class FileSystemWrapper extends FileSystem {
return
IOUtils
.
setReadOnly
(
unwrap
(
fileName
));
}
public
void
createDir
s
(
String
file
Name
)
{
IOUtils
.
createDir
s
(
unwrap
(
file
Name
));
public
void
createDir
ectory
(
String
directory
Name
)
{
IOUtils
.
createDir
ectory
(
unwrap
(
directory
Name
));
}
public
boolean
createNewFile
(
String
fileName
)
{
...
...
@@ -50,10 +50,6 @@ public abstract class FileSystemWrapper extends FileSystem {
IOUtils
.
delete
(
unwrap
(
fileName
));
}
public
void
deleteRecursive
(
String
directory
,
boolean
tryOnly
)
{
IOUtils
.
deleteRecursive
(
unwrap
(
directory
),
tryOnly
);
}
public
boolean
exists
(
String
fileName
)
{
return
IOUtils
.
exists
(
unwrap
(
fileName
));
}
...
...
h2/src/main/org/h2/store/fs/FileSystemZip.java
浏览文件 @
6992e031
...
...
@@ -33,7 +33,7 @@ public class FileSystemZip extends FileSystem {
return
false
;
}
public
void
createDir
s
(
String
file
Name
)
{
public
void
createDir
ectory
(
String
directory
Name
)
{
// ignore
}
...
...
@@ -52,10 +52,6 @@ public class FileSystemZip extends FileSystem {
throw
DbException
.
getUnsupportedException
(
"write"
);
}
public
void
deleteRecursive
(
String
fileName
,
boolean
tryOnly
)
{
throw
DbException
.
getUnsupportedException
(
"write"
);
}
public
boolean
exists
(
String
fileName
)
{
try
{
String
entryName
=
getEntryName
(
fileName
);
...
...
h2/src/main/org/h2/store/fs/Recorder.java
浏览文件 @
6992e031
...
...
@@ -18,9 +18,9 @@ public interface Recorder {
int
COPY
=
3
;
/**
* Create a
ll parent directories
.
* Create a
directory
.
*/
int
CREATE_DIR
S
=
4
;
int
CREATE_DIR
ECTORY
=
4
;
/**
* Create a new file.
...
...
@@ -37,21 +37,16 @@ public interface Recorder {
*/
int
DELETE
=
7
;
/**
* Delete all files and directories recursively.
*/
int
DELETE_RECURSIVE
=
8
;
/**
* Open a file output stream.
*/
int
OPEN_OUTPUT_STREAM
=
9
;
int
OPEN_OUTPUT_STREAM
=
8
;
/**
* Rename a file. The file name contains the source and the target file
* separated with a colon.
*/
int
RENAME
=
10
;
int
RENAME
=
9
;
/**
* Set the length of the file.
...
...
h2/src/main/org/h2/store/fs/RecordingFileSystem.java
浏览文件 @
6992e031
...
...
@@ -41,9 +41,9 @@ public class RecordingFileSystem extends FileSystemWrapper {
RecordingFileSystem
.
recorder
=
recorder
;
}
public
void
createDir
s
(
String
file
Name
)
{
log
(
Recorder
.
CREATE_DIR
S
,
unwrap
(
file
Name
));
super
.
createDir
s
(
file
Name
);
public
void
createDir
ectories
(
String
directory
Name
)
{
log
(
Recorder
.
CREATE_DIR
ECTORY
,
unwrap
(
directory
Name
));
super
.
createDir
ectory
(
directory
Name
);
}
public
boolean
createNewFile
(
String
fileName
)
{
...
...
@@ -62,11 +62,6 @@ public class RecordingFileSystem extends FileSystemWrapper {
super
.
delete
(
fileName
);
}
public
void
deleteRecursive
(
String
directory
,
boolean
tryOnly
)
{
log
(
Recorder
.
DELETE_RECURSIVE
,
unwrap
(
directory
));
super
.
deleteRecursive
(
directory
,
tryOnly
);
}
public
FileObject
openFileObject
(
String
fileName
,
String
mode
)
throws
IOException
{
return
new
RecordingFileObject
(
this
,
super
.
openFileObject
(
fileName
,
mode
));
}
...
...
h2/src/main/org/h2/util/IOUtils.java
浏览文件 @
6992e031
...
...
@@ -735,12 +735,12 @@ public class IOUtils {
}
/**
* Create a
ll required directories that are required for this file
.
* Create a
directory (all required parent directories already exist)
.
*
* @param
fileName the file name (not directory name)
* @param
directoryName the directory name
*/
public
static
void
createDir
s
(
String
file
Name
)
{
getFileSystem
(
fileName
).
createDirs
(
file
Name
);
public
static
void
createDir
ectory
(
String
directory
Name
)
{
getFileSystem
(
directoryName
).
createDirectory
(
directory
Name
);
}
/**
...
...
@@ -752,16 +752,6 @@ public class IOUtils {
getFileSystem
(
fileName
).
delete
(
fileName
);
}
/**
* Delete a directory or file and all subdirectories and files.
*
* @param directory the directory
* @param tryOnly whether errors should be ignored
*/
public
static
void
deleteRecursive
(
String
directory
,
boolean
tryOnly
)
{
getFileSystem
(
directory
).
deleteRecursive
(
directory
,
tryOnly
);
}
/**
* Get the last modified date of a file.
*
...
...
@@ -800,4 +790,38 @@ public class IOUtils {
}
}
/**
* Delete a directory or file and all subdirectories and files.
*
* @param path the path
* @param tryOnly whether errors should be ignored
*/
public
static
void
deleteRecursive
(
String
path
,
boolean
tryOnly
)
{
if
(
exists
(
path
))
{
if
(
isDirectory
(
path
))
{
for
(
String
s
:
listFiles
(
path
))
{
deleteRecursive
(
s
,
tryOnly
);
}
}
if
(
tryOnly
)
{
tryDelete
(
path
);
}
else
{
delete
(
path
);
}
}
}
/**
* Create the directory and all required parent directories.
*
* @param dir the directory name
*/
public
static
void
createDirectories
(
String
dir
)
{
String
parent
=
getParent
(
dir
);
if
(!
exists
(
parent
))
{
createDirectories
(
parent
);
}
createDirectory
(
dir
);
}
}
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
6992e031
...
...
@@ -10,7 +10,6 @@ import java.sql.SQLException;
import
java.util.Properties
;
import
org.h2.Driver
;
import
org.h2.engine.Constants
;
import
org.h2.store.fs.FileSystemDisk
;
import
org.h2.store.fs.RecordingFileSystem
;
import
org.h2.test.bench.TestPerformance
;
import
org.h2.test.db.TestAlter
;
...
...
@@ -165,6 +164,7 @@ import org.h2.test.utils.OutputCatcher;
import
org.h2.test.utils.SelfDestructor
;
import
org.h2.tools.DeleteDbFiles
;
import
org.h2.tools.Server
;
import
org.h2.util.IOUtils
;
import
org.h2.util.Profiler
;
import
org.h2.util.Utils
;
import
org.h2.util.StringUtils
;
...
...
@@ -714,9 +714,9 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
*/
void
beforeTest
()
throws
SQLException
{
Driver
.
load
();
FileSystemDisk
.
getInstance
()
.
deleteRecursive
(
TestBase
.
BASE_TEST_DIR
,
true
);
IOUtils
.
deleteRecursive
(
TestBase
.
BASE_TEST_DIR
,
true
);
DeleteDbFiles
.
execute
(
TestBase
.
BASE_TEST_DIR
,
null
,
true
);
FileSystemDisk
.
getInstance
()
.
deleteRecursive
(
"trace.db"
,
false
);
IOUtils
.
deleteRecursive
(
"trace.db"
,
false
);
if
(
networked
)
{
String
[]
args
=
ssl
?
new
String
[]
{
"-tcpSSL"
,
"true"
,
"-tcpPort"
,
"9192"
}
:
new
String
[]
{
"-tcpPort"
,
"9192"
};
...
...
@@ -731,11 +731,11 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
}
private
void
afterTest
()
{
FileSystemDisk
.
getInstance
()
.
deleteRecursive
(
"trace.db"
,
true
);
IOUtils
.
deleteRecursive
(
"trace.db"
,
true
);
if
(
networked
&&
server
!=
null
)
{
server
.
stop
();
}
FileSystemDisk
.
getInstance
()
.
deleteRecursive
(
TestBase
.
BASE_TEST_DIR
,
true
);
IOUtils
.
deleteRecursive
(
TestBase
.
BASE_TEST_DIR
,
true
);
}
/**
...
...
h2/src/test/org/h2/test/db/TestFullText.java
浏览文件 @
6992e031
...
...
@@ -15,7 +15,6 @@ import java.sql.Statement;
import
java.util.Random
;
import
java.util.StringTokenizer
;
import
org.h2.fulltext.FullText
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
import
org.h2.util.Task
;
...
...
@@ -182,7 +181,7 @@ public class TestFullText extends TestBase {
FullText
.
dropAll
(
conn
);
conn
.
close
();
deleteDb
(
"fullTextTransaction"
);
FileSystem
.
getInstance
(
getBaseDir
())
.
deleteRecursive
(
getBaseDir
()
+
"/fullTextTransaction"
,
false
);
IOUtils
.
deleteRecursive
(
getBaseDir
()
+
"/fullTextTransaction"
,
false
);
}
private
void
testMultiThreaded
(
boolean
lucene
)
throws
Exception
{
...
...
@@ -332,7 +331,7 @@ public class TestFullText extends TestBase {
stat
=
conn
.
createStatement
();
stat
.
execute
(
"INSERT INTO TEST VALUES(3, 'Hello')"
);
conn
.
close
();
FileSystem
.
getInstance
(
getBaseDir
())
.
deleteRecursive
(
getBaseDir
()
+
"/fullTextReopen"
,
false
);
IOUtils
.
deleteRecursive
(
getBaseDir
()
+
"/fullTextReopen"
,
false
);
}
private
void
testPerformance
(
boolean
lucene
)
throws
SQLException
{
...
...
h2/src/test/org/h2/test/poweroff/TestRecoverKillLoop.java
浏览文件 @
6992e031
...
...
@@ -8,9 +8,9 @@ package org.h2.test.poweroff;
import
java.io.InputStream
;
import
java.util.Random
;
import
org.h2.store.fs.FileSystemDisk
;
import
org.h2.test.TestBase
;
import
org.h2.test.synth.OutputCatcher
;
import
org.h2.util.IOUtils
;
/**
* Run the TestRecover test case in a loop. The process is killed after 10
...
...
@@ -33,7 +33,7 @@ public class TestRecoverKillLoop extends TestBase {
}
private
void
runTest
(
int
count
)
throws
Exception
{
FileSystemDisk
.
getInstance
()
.
deleteRecursive
(
"data/db"
,
false
);
IOUtils
.
deleteRecursive
(
"data/db"
,
false
);
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
String
[]
procDef
=
{
...
...
h2/src/test/org/h2/test/server/TestInit.java
浏览文件 @
6992e031
...
...
@@ -35,7 +35,7 @@ public class TestInit extends TestBase {
String
init2
=
getBaseDir
()
+
"/test-init-2.sql"
;
// Create two scripts that we will run via "INIT"
IOUtils
.
createDir
s
(
init1
);
IOUtils
.
createDir
ectories
(
IOUtils
.
getParent
(
init1
)
);
Writer
w
=
new
OutputStreamWriter
(
IOUtils
.
openFileOutputStream
(
init1
,
false
));
...
...
h2/src/test/org/h2/test/unit/FileSystemDatabase.java
浏览文件 @
6992e031
...
...
@@ -19,7 +19,6 @@ import java.sql.Statement;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Properties
;
import
org.h2.Driver
;
import
org.h2.message.DbException
;
import
org.h2.store.fs.FileObject
;
...
...
@@ -175,34 +174,17 @@ public class FileSystemDatabase extends FileSystem {
return
true
;
}
public
void
createDir
s
(
String
file
Name
)
{
fileName
=
unwrap
(
file
Name
);
public
void
createDir
ectory
(
String
directory
Name
)
{
directoryName
=
unwrap
(
directory
Name
);
try
{
String
[]
path
=
StringUtils
.
arraySplit
(
fileName
,
'/'
,
false
);
long
parentId
=
0
;
int
len
=
path
.
length
;
if
(
fileName
.
endsWith
(
"/"
))
{
len
--;
}
len
--;
for
(
int
i
=
1
;
i
<
len
;
i
++)
{
PreparedStatement
prep
=
prepare
(
"SELECT ID FROM FILES WHERE PARENTID=? AND NAME=?"
);
prep
.
setLong
(
1
,
parentId
);
prep
.
setString
(
2
,
path
[
i
]);
ResultSet
rs
=
prep
.
executeQuery
();
if
(!
rs
.
next
())
{
prep
=
prepare
(
"INSERT INTO FILES(NAME, PARENTID, LASTMODIFIED) VALUES(?, ?, ?)"
);
prep
.
setString
(
1
,
path
[
i
]);
prep
.
setLong
(
2
,
parentId
);
prep
.
setLong
(
3
,
System
.
currentTimeMillis
());
prep
.
execute
();
rs
=
prep
.
getGeneratedKeys
();
rs
.
next
();
parentId
=
rs
.
getLong
(
1
);
}
else
{
parentId
=
rs
.
getLong
(
1
);
}
}
String
parent
=
getParent
(
directoryName
);
String
name
=
getFileName
(
directoryName
);
long
parentId
=
getId
(
parent
,
false
);
PreparedStatement
prep
=
prepare
(
"INSERT INTO FILES(NAME, PARENTID, LASTMODIFIED) VALUES(?, ?, ?)"
);
prep
.
setString
(
1
,
name
);
prep
.
setLong
(
2
,
parentId
);
prep
.
setLong
(
3
,
System
.
currentTimeMillis
());
prep
.
execute
();
commit
();
}
catch
(
SQLException
e
)
{
rollback
();
...
...
@@ -238,10 +220,6 @@ public class FileSystemDatabase extends FileSystem {
}
}
public
void
deleteRecursive
(
String
fileName
,
boolean
tryOnly
)
{
throw
DbException
.
getUnsupportedException
(
"db"
);
}
public
boolean
exists
(
String
fileName
)
{
long
id
=
getId
(
fileName
,
false
);
return
id
>=
0
;
...
...
h2/src/test/org/h2/test/unit/TestFileSystem.java
浏览文件 @
6992e031
...
...
@@ -90,7 +90,7 @@ public class TestFileSystem extends TestBase {
fs
.
openFileOutputStream
(
"memFS:data/test/a.txt"
,
false
).
close
();
String
[]
list
=
fs
.
listFiles
(
"memFS:data/test"
);
assertEquals
(
1
,
list
.
length
);
f
s
.
deleteRecursive
(
"memFS:"
,
false
);
IOUtil
s
.
deleteRecursive
(
"memFS:"
,
false
);
}
private
void
testClasspath
()
throws
IOException
{
...
...
@@ -217,7 +217,7 @@ public class TestFileSystem extends TestBase {
for
(
String
s
:
fs
.
listFiles
(
fsBase
))
{
fs
.
delete
(
s
);
}
fs
.
createDirs
(
fsBase
+
"/test/x
"
);
IOUtils
.
createDirectories
(
fsBase
+
"/test
"
);
fs
.
delete
(
fsBase
+
"/test"
);
fs
.
delete
(
fsBase
+
"/test2"
);
assertTrue
(
fs
.
createNewFile
(
fsBase
+
"/test"
));
...
...
@@ -277,10 +277,10 @@ public class TestFileSystem extends TestBase {
assertTrue
(
fs
.
tryDelete
(
fsBase
+
"/test2"
));
fs
.
delete
(
fsBase
+
"/test"
);
if
(
fsBase
.
indexOf
(
FileSystemMemory
.
PREFIX
)
<
0
&&
fsBase
.
indexOf
(
FileSystemMemory
.
PREFIX_LZF
)
<
0
)
{
fs
.
createDirs
(
fsBase
+
"/testDir/test
"
);
IOUtils
.
createDirectories
(
fsBase
+
"/testDir
"
);
assertTrue
(
fs
.
isDirectory
(
fsBase
+
"/testDir"
));
if
(!
fsBase
.
startsWith
(
"jdbc:"
))
{
f
s
.
deleteRecursive
(
fsBase
+
"/testDir"
,
false
);
IOUtil
s
.
deleteRecursive
(
fsBase
+
"/testDir"
,
false
);
assertTrue
(!
fs
.
exists
(
fsBase
+
"/testDir"
));
}
}
...
...
h2/src/test/org/h2/test/unit/TestStreams.java
浏览文件 @
6992e031
...
...
@@ -53,7 +53,7 @@ public class TestStreams extends TestBase {
private
void
testLZFStreamClose
()
throws
IOException
{
String
fileName
=
getBaseDir
()
+
"/temp"
;
IOUtils
.
createDir
s
(
fileName
);
IOUtils
.
createDir
ectories
(
IOUtils
.
getParent
(
fileName
)
);
OutputStream
fo
=
IOUtils
.
openFileOutputStream
(
fileName
,
false
);
LZFOutputStream
out
=
new
LZFOutputStream
(
fo
);
out
.
write
(
"Hello"
.
getBytes
());
...
...
h2/src/test/org/h2/test/utils/DebugFileSystem.java
浏览文件 @
6992e031
...
...
@@ -65,9 +65,9 @@ public class DebugFileSystem extends FileSystemWrapper {
return
super
.
canWrite
(
fileName
);
}
public
void
createDir
s
(
String
file
Name
)
{
trace
(
fileName
,
"createDirs
"
);
super
.
createDir
s
(
file
Name
);
public
void
createDir
ectory
(
String
directory
Name
)
{
trace
(
directoryName
,
"createDirectory
"
);
super
.
createDir
ectory
(
directory
Name
);
}
public
boolean
createNewFile
(
String
fileName
)
{
...
...
@@ -86,11 +86,6 @@ public class DebugFileSystem extends FileSystemWrapper {
super
.
delete
(
fileName
);
}
public
void
deleteRecursive
(
String
directory
,
boolean
tryOnly
)
{
trace
(
directory
,
"deleteRecursive"
,
tryOnly
);
super
.
deleteRecursive
(
directory
,
tryOnly
);
}
public
boolean
exists
(
String
fileName
)
{
trace
(
fileName
,
"exists"
);
return
super
.
exists
(
fileName
);
...
...
h2/src/tools/org/h2/dev/fs/FileShell.java
浏览文件 @
6992e031
...
...
@@ -225,9 +225,9 @@ public class FileShell extends Tool {
println
(
buff
.
toString
());
}
}
else
if
(
"mkdir"
.
equals
(
c
))
{
String
dir
=
getFile
(
list
[
i
++]
+
"/dummy"
);
String
dir
=
getFile
(
list
[
i
++]);
end
(
list
,
i
);
IOUtils
.
createDirs
(
dir
);
IOUtils
.
createDir
ectorie
s
(
dir
);
}
else
if
(
"mv"
.
equals
(
c
))
{
String
source
=
getFile
(
list
[
i
++]);
String
target
=
getFile
(
list
[
i
++]);
...
...
h2/src/tools/org/h2/dev/fs/FileSystemZip2.java
浏览文件 @
6992e031
...
...
@@ -48,7 +48,7 @@ public class FileSystemZip2 extends FileSystem {
return
false
;
}
public
void
createDir
s
(
String
file
Name
)
{
public
void
createDir
ectory
(
String
directory
Name
)
{
// ignore
}
...
...
@@ -67,10 +67,6 @@ public class FileSystemZip2 extends FileSystem {
throw
DbException
.
getUnsupportedException
(
"write"
);
}
public
void
deleteRecursive
(
String
fileName
,
boolean
tryOnly
)
{
throw
DbException
.
getUnsupportedException
(
"write"
);
}
public
boolean
exists
(
String
fileName
)
{
try
{
String
entryName
=
getEntryName
(
fileName
);
...
...
h2/src/tools/org/h2/dev/ftp/server/FtpControl.java
浏览文件 @
6992e031
...
...
@@ -16,6 +16,7 @@ import java.net.ServerSocket;
import
java.net.Socket
;
import
org.h2.engine.Constants
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.util.IOUtils
;
import
org.h2.util.StringUtils
;
/**
...
...
@@ -355,7 +356,7 @@ public class FtpControl extends Thread {
boolean
ok
=
false
;
if
(!
readonly
)
{
try
{
fs
.
createDirs
(
fileName
+
"/x"
);
IOUtils
.
createDirectories
(
fileName
);
reply
(
257
,
StringUtils
.
quoteIdentifier
(
param
)
+
" directory"
);
ok
=
true
;
}
catch
(
Exception
e
)
{
...
...
h2/src/tools/org/h2/dev/ftp/server/FtpServer.java
浏览文件 @
6992e031
...
...
@@ -354,7 +354,7 @@ public class FtpServer extends Tool implements Service {
public
void
start
()
{
fs
=
FileSystem
.
getInstance
(
root
);
root
=
fs
.
getCanonicalPath
(
root
);
fs
.
createDirs
(
root
+
"/x"
);
IOUtils
.
createDirectories
(
root
);
serverSocket
=
NetUtils
.
createServerSocket
(
port
,
false
);
port
=
serverSocket
.
getLocalPort
();
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论