mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 07:12:17 +00:00
WalletAppKit/SPVBlockStore: release the file lock explicitly when closing, as otherwise apps that try to shut down the store then delete the file can crash on Windows.
This commit is contained in:
parent
a698c5846e
commit
068da489ef
@ -40,6 +40,7 @@ import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.channels.FileLock;
|
||||
import java.nio.file.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
@ -275,8 +276,7 @@ public class WalletAppKit extends AbstractIdleService {
|
||||
if (chainFileExists) {
|
||||
log.info("Deleting the chain file in preparation from restore.");
|
||||
vStore.close();
|
||||
if (!chainFile.delete())
|
||||
throw new Exception("Failed to delete chain file in preparation for restore.");
|
||||
Files.delete(chainFile.toPath());
|
||||
vStore = new SPVBlockStore(params, chainFile);
|
||||
}
|
||||
} else {
|
||||
@ -286,8 +286,7 @@ public class WalletAppKit extends AbstractIdleService {
|
||||
} else if (chainFileExists) {
|
||||
log.info("Deleting the chain file in preparation from restore.");
|
||||
vStore.close();
|
||||
if (!chainFile.delete())
|
||||
throw new Exception("Failed to delete chain file in preparation for restore.");
|
||||
Files.delete(chainFile.toPath());
|
||||
vStore = new SPVBlockStore(params, chainFile);
|
||||
}
|
||||
}
|
||||
|
@ -271,6 +271,7 @@ public class SPVBlockStore implements BlockStore {
|
||||
buffer.force();
|
||||
buffer = null; // Allow it to be GCd and the underlying file mapping to go away.
|
||||
randomAccessFile.close();
|
||||
fileLock.release();
|
||||
} catch (IOException e) {
|
||||
throw new BlockStoreException(e);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user