fix import of encrypted json wallet on linux

This commit is contained in:
Craig Raw 2021-11-13 10:05:05 +02:00
parent c566dea232
commit cb41a1ed66
2 changed files with 8 additions and 4 deletions

View file

@ -101,9 +101,12 @@ public class Sparrow implements WalletImport, WalletExport {
java.nio.file.Files.copy(inputStream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING); java.nio.file.Files.copy(inputStream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
PersistenceType persistenceType = Storage.detectPersistenceType(tempFile); PersistenceType persistenceType = Storage.detectPersistenceType(tempFile);
persistenceType = (persistenceType == null ? PersistenceType.JSON : persistenceType); persistenceType = (persistenceType == null ? PersistenceType.JSON : persistenceType);
if(persistenceType != PersistenceType.JSON || !isEncrypted(tempFile)) {
File tempTypedFile = new File(tempFile.getParentFile(), tempFile.getName() + "." + persistenceType.getExtension()); File tempTypedFile = new File(tempFile.getParentFile(), tempFile.getName() + "." + persistenceType.getExtension());
tempFile.renameTo(tempTypedFile); tempFile.renameTo(tempTypedFile);
tempFile = tempTypedFile; tempFile = tempTypedFile;
}
storage = new Storage(persistenceType, tempFile); storage = new Storage(persistenceType, tempFile);
if(!isEncrypted(tempFile)) { if(!isEncrypted(tempFile)) {
wallet = storage.loadUnencryptedWallet().getWallet(); wallet = storage.loadUnencryptedWallet().getWallet();

View file

@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions; import java.nio.file.attribute.PosixFilePermissions;
@ -373,7 +374,7 @@ public class Storage {
} }
public static PersistenceType detectPersistenceType(File walletFile) { public static PersistenceType detectPersistenceType(File walletFile) {
try(Reader reader = new FileReader(walletFile)) { try(Reader reader = new FileReader(walletFile, StandardCharsets.UTF_8)) {
int firstChar = reader.read(); int firstChar = reader.read();
if(firstChar == 'U' || firstChar == '{') { if(firstChar == 'U' || firstChar == '{') {