mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-05 05:46:44 +00:00
reduce file reads on db files to avoid locking exception on windows
This commit is contained in:
parent
7f178b5f67
commit
445db6a4d6
1 changed files with 8 additions and 14 deletions
|
@ -126,13 +126,6 @@ public class DbPersistence implements Persistence {
|
||||||
File walletFile = storage.getWalletFile();
|
File walletFile = storage.getWalletFile();
|
||||||
walletFile = renameToDbFile(walletFile);
|
walletFile = renameToDbFile(walletFile);
|
||||||
|
|
||||||
if(walletFile.exists() && isEncrypted(walletFile)) {
|
|
||||||
if(dataSource != null && !dataSource.isClosed()) {
|
|
||||||
dataSource.close();
|
|
||||||
}
|
|
||||||
walletFile.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePassword(storage, null);
|
updatePassword(storage, null);
|
||||||
cleanAndAddWallet(storage, wallet, null);
|
cleanAndAddWallet(storage, wallet, null);
|
||||||
|
|
||||||
|
@ -144,13 +137,6 @@ public class DbPersistence implements Persistence {
|
||||||
File walletFile = storage.getWalletFile();
|
File walletFile = storage.getWalletFile();
|
||||||
walletFile = renameToDbFile(walletFile);
|
walletFile = renameToDbFile(walletFile);
|
||||||
|
|
||||||
if(walletFile.exists() && !isEncrypted(walletFile)) {
|
|
||||||
if(dataSource != null && !dataSource.isClosed()) {
|
|
||||||
dataSource.close();
|
|
||||||
}
|
|
||||||
walletFile.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean existing = walletFile.exists();
|
boolean existing = walletFile.exists();
|
||||||
updatePassword(storage, encryptionPubKey);
|
updatePassword(storage, encryptionPubKey);
|
||||||
cleanAndAddWallet(storage, wallet, getFilePassword(encryptionPubKey));
|
cleanAndAddWallet(storage, wallet, getFilePassword(encryptionPubKey));
|
||||||
|
@ -344,6 +330,10 @@ public class DbPersistence implements Persistence {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeBinaryHeader(File walletFile) throws IOException {
|
private void writeBinaryHeader(File walletFile) throws IOException {
|
||||||
|
if(dataSource != null && !dataSource.isClosed()) {
|
||||||
|
dataSource.close();
|
||||||
|
}
|
||||||
|
|
||||||
ByteBuffer header = ByteBuffer.allocate(HEADER_MAGIC_1.length + SALT_LENGTH_BYTES);
|
ByteBuffer header = ByteBuffer.allocate(HEADER_MAGIC_1.length + SALT_LENGTH_BYTES);
|
||||||
header.put(HEADER_MAGIC_1);
|
header.put(HEADER_MAGIC_1);
|
||||||
header.put(keyDeriver.getSalt());
|
header.put(keyDeriver.getSalt());
|
||||||
|
@ -454,6 +444,10 @@ public class DbPersistence implements Persistence {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEncrypted(File walletFile) throws IOException {
|
public boolean isEncrypted(File walletFile) throws IOException {
|
||||||
|
if(dataSource != null) {
|
||||||
|
return getDatasourcePassword() != null;
|
||||||
|
}
|
||||||
|
|
||||||
byte[] header = new byte[H2_ENCRYPT_HEADER.length];
|
byte[] header = new byte[H2_ENCRYPT_HEADER.length];
|
||||||
try(InputStream inputStream = new FileInputStream(walletFile)) {
|
try(InputStream inputStream = new FileInputStream(walletFile)) {
|
||||||
inputStream.read(header, 0, H2_ENCRYPT_HEADER.length);
|
inputStream.read(header, 0, H2_ENCRYPT_HEADER.length);
|
||||||
|
|
Loading…
Reference in a new issue