mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 06:44:16 +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.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.nio.channels.FileLock;
|
import java.nio.channels.FileLock;
|
||||||
|
import java.nio.file.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
@ -275,8 +276,7 @@ public class WalletAppKit extends AbstractIdleService {
|
|||||||
if (chainFileExists) {
|
if (chainFileExists) {
|
||||||
log.info("Deleting the chain file in preparation from restore.");
|
log.info("Deleting the chain file in preparation from restore.");
|
||||||
vStore.close();
|
vStore.close();
|
||||||
if (!chainFile.delete())
|
Files.delete(chainFile.toPath());
|
||||||
throw new Exception("Failed to delete chain file in preparation for restore.");
|
|
||||||
vStore = new SPVBlockStore(params, chainFile);
|
vStore = new SPVBlockStore(params, chainFile);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -286,8 +286,7 @@ public class WalletAppKit extends AbstractIdleService {
|
|||||||
} else if (chainFileExists) {
|
} else if (chainFileExists) {
|
||||||
log.info("Deleting the chain file in preparation from restore.");
|
log.info("Deleting the chain file in preparation from restore.");
|
||||||
vStore.close();
|
vStore.close();
|
||||||
if (!chainFile.delete())
|
Files.delete(chainFile.toPath());
|
||||||
throw new Exception("Failed to delete chain file in preparation for restore.");
|
|
||||||
vStore = new SPVBlockStore(params, chainFile);
|
vStore = new SPVBlockStore(params, chainFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,6 +271,7 @@ public class SPVBlockStore implements BlockStore {
|
|||||||
buffer.force();
|
buffer.force();
|
||||||
buffer = null; // Allow it to be GCd and the underlying file mapping to go away.
|
buffer = null; // Allow it to be GCd and the underlying file mapping to go away.
|
||||||
randomAccessFile.close();
|
randomAccessFile.close();
|
||||||
|
fileLock.release();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new BlockStoreException(e);
|
throw new BlockStoreException(e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user