3
0
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:
Mike Hearn 2015-01-22 18:09:07 +01:00
parent a698c5846e
commit 068da489ef
2 changed files with 4 additions and 4 deletions

View File

@ -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);
} }
} }

View File

@ -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);
} }