提交 51a00e71 authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved compatibility with the Java 7 FileSystem abstraction.

上级 bd00e7d3
...@@ -431,7 +431,7 @@ public class FileStore { ...@@ -431,7 +431,7 @@ public class FileStore {
*/ */
public void sync() { public void sync() {
try { try {
file.sync(); file.force(true);
} catch (IOException e) { } catch (IOException e) {
throw DbException.convertIOException(e, name); throw DbException.convertIOException(e, name);
} }
......
...@@ -58,9 +58,11 @@ public interface FileObject { ...@@ -58,9 +58,11 @@ public interface FileObject {
long position() throws IOException; long position() throws IOException;
/** /**
* Force changes to the physical location. * Force changes to the physical location (sync).
*
* @param metaData whether the file metadata should be written as well
*/ */
void sync() throws IOException; void force(boolean metaData) throws IOException;
/** /**
* Change the length of the file. * Change the length of the file.
......
...@@ -25,7 +25,7 @@ public class FileObjectDisk implements FileObject { ...@@ -25,7 +25,7 @@ public class FileObjectDisk implements FileObject {
this.name = fileName; this.name = fileName;
} }
public void sync() throws IOException { public void force(boolean metaData) throws IOException {
String m = SysProperties.SYNC_METHOD; String m = SysProperties.SYNC_METHOD;
if ("".equals(m)) { if ("".equals(m)) {
// do nothing // do nothing
......
...@@ -57,7 +57,7 @@ public class FileObjectMem implements FileObject { ...@@ -57,7 +57,7 @@ public class FileObjectMem implements FileObject {
pos = 0; pos = 0;
} }
public void sync() { public void force(boolean metaData) throws IOException {
// do nothing // do nothing
} }
......
...@@ -78,8 +78,8 @@ public class FileObjectNio implements FileObject { ...@@ -78,8 +78,8 @@ public class FileObjectNio implements FileObject {
length = newLength; length = newLength;
} }
public void sync() throws IOException { public void force(boolean metaData) throws IOException {
channel.force(true); channel.force(metaData);
} }
public void write(byte[] b, int off, int len) throws IOException { public void write(byte[] b, int off, int len) throws IOException {
......
...@@ -186,7 +186,7 @@ public class FileObjectNioMapped implements FileObject { ...@@ -186,7 +186,7 @@ public class FileObjectNioMapped implements FileObject {
pos = (int) Math.min(newLength, oldPos); pos = (int) Math.min(newLength, oldPos);
} }
public synchronized void sync() throws IOException { public void force(boolean metaData) throws IOException {
mapped.force(); mapped.force();
file.getFD().sync(); file.getFD().sync();
} }
......
...@@ -49,8 +49,8 @@ public class FileObjectRec implements FileObject { ...@@ -49,8 +49,8 @@ public class FileObjectRec implements FileObject {
file.truncate(newLength); file.truncate(newLength);
} }
public void sync() throws IOException { public void force(boolean metaData) throws IOException {
file.sync(); file.force(metaData);
} }
public void write(byte[] b, int off, int len) throws IOException { public void write(byte[] b, int off, int len) throws IOException {
......
...@@ -114,9 +114,9 @@ public class FileObjectSplit implements FileObject { ...@@ -114,9 +114,9 @@ public class FileObjectSplit implements FileObject {
this.length = newLength; this.length = newLength;
} }
public void sync() throws IOException { public void force(boolean metaData) throws IOException {
for (FileObject f : list) { for (FileObject f : list) {
f.sync(); f.force(metaData);
} }
} }
......
...@@ -96,7 +96,7 @@ public class FileObjectZip implements FileObject { ...@@ -96,7 +96,7 @@ public class FileObjectZip implements FileObject {
throw new IOException("File is read-only"); throw new IOException("File is read-only");
} }
public void sync() { public void force(boolean metaData) throws IOException {
// nothing to do // nothing to do
} }
......
...@@ -316,7 +316,7 @@ public class TestFileSystem extends TestBase { ...@@ -316,7 +316,7 @@ public class TestFileSystem extends TestBase {
FileUtils.delete(s); FileUtils.delete(s);
FileObject f = FileUtils.openFileObject(s, "rw"); FileObject f = FileUtils.openFileObject(s, "rw");
assertThrows(EOFException.class, f).readFully(new byte[1], 0, 1); assertThrows(EOFException.class, f).readFully(new byte[1], 0, 1);
f.sync(); f.force(true);
Random random = new Random(seed); Random random = new Random(seed);
int size = getSize(100, 500); int size = getSize(100, 500);
try { try {
......
...@@ -56,9 +56,9 @@ public class FileDebug implements FileObject { ...@@ -56,9 +56,9 @@ public class FileDebug implements FileObject {
file.truncate(newLength); file.truncate(newLength);
} }
public void sync() throws IOException { public void force(boolean metaData) throws IOException {
debug("sync"); debug("force");
file.sync(); file.force(metaData);
} }
public void write(byte[] b, int off, int len) throws IOException { public void write(byte[] b, int off, int len) throws IOException {
......
...@@ -85,8 +85,8 @@ public class FileObjectCrypt implements FileObject { ...@@ -85,8 +85,8 @@ public class FileObjectCrypt implements FileObject {
file.position(pos + HEADER_LENGTH); file.position(pos + HEADER_LENGTH);
} }
public void sync() throws IOException { public void force(boolean metaData) throws IOException {
file.sync(); file.force(metaData);
} }
public FileLock tryLock() throws IOException { public FileLock tryLock() throws IOException {
......
...@@ -102,7 +102,7 @@ public class FileObjectZip2 implements FileObject { ...@@ -102,7 +102,7 @@ public class FileObjectZip2 implements FileObject {
throw new IOException("File is read-only"); throw new IOException("File is read-only");
} }
public void sync() { public void force(boolean metaData) throws IOException {
// nothing to do // nothing to do
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论