mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Cleanup fileChannel if file locking fails
This commit is contained in:
parent
53f47d42fc
commit
7ac6c9a170
1 changed files with 17 additions and 9 deletions
|
@ -884,6 +884,7 @@ public class SignalAccount implements Closeable {
|
||||||
|
|
||||||
private static Pair<FileChannel, FileLock> openFileChannel(File fileName, boolean waitForLock) throws IOException {
|
private static Pair<FileChannel, FileLock> openFileChannel(File fileName, boolean waitForLock) throws IOException {
|
||||||
var fileChannel = new RandomAccessFile(fileName, "rw").getChannel();
|
var fileChannel = new RandomAccessFile(fileName, "rw").getChannel();
|
||||||
|
try {
|
||||||
var lock = fileChannel.tryLock();
|
var lock = fileChannel.tryLock();
|
||||||
if (lock == null) {
|
if (lock == null) {
|
||||||
if (!waitForLock) {
|
if (!waitForLock) {
|
||||||
|
@ -894,7 +895,14 @@ public class SignalAccount implements Closeable {
|
||||||
lock = fileChannel.lock();
|
lock = fileChannel.lock();
|
||||||
logger.info("Config file lock acquired.");
|
logger.info("Config file lock acquired.");
|
||||||
}
|
}
|
||||||
return new Pair<>(fileChannel, lock);
|
final var result = new Pair<>(fileChannel, lock);
|
||||||
|
fileChannel = null;
|
||||||
|
return result;
|
||||||
|
} finally {
|
||||||
|
if (fileChannel != null) {
|
||||||
|
fileChannel.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPreKeys(ServiceIdType serviceIdType, List<PreKeyRecord> records) {
|
public void addPreKeys(ServiceIdType serviceIdType, List<PreKeyRecord> records) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue