提交 845fd2e6 authored 作者: Thomas Mueller's avatar Thomas Mueller

Close file when locking fails

上级 9d4901f7
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.store; package org.h2.store;
import java.io.IOException;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -48,14 +49,22 @@ public class FileLister { ...@@ -48,14 +49,22 @@ public class FileLister {
ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1, message).getSQLException(); ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1, message).getSQLException();
} }
} else if (fileName.endsWith(Constants.SUFFIX_MV_FILE)) { } else if (fileName.endsWith(Constants.SUFFIX_MV_FILE)) {
FileChannel f = null;
try { try {
FileChannel f = FilePath.get(fileName).open("r"); f = FilePath.get(fileName).open("r");
java.nio.channels.FileLock lock = f.tryLock(0, Long.MAX_VALUE, true); java.nio.channels.FileLock lock = f.tryLock(0, Long.MAX_VALUE, true);
lock.release(); lock.release();
f.close();
} catch (Exception e) { } catch (Exception e) {
throw DbException.get( throw DbException.get(
ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1, e, message).getSQLException(); ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1, e, message).getSQLException();
} finally {
if (f != null) {
try {
f.close();
} catch (IOException e) {
// ignore
}
}
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论