mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-05-10 10:35:02 -04:00
support rolling backup of multisig wallets
This commit is contained in:
parent
f17c5803b5
commit
c28108a4b6
4 changed files with 45 additions and 21 deletions
|
@ -18,7 +18,7 @@
|
|||
package bisq.common.crypto;
|
||||
|
||||
import bisq.common.config.Config;
|
||||
|
||||
import bisq.common.file.FileUtil;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
@ -139,6 +139,7 @@ public class KeyStorage {
|
|||
* @param secretKey The symmetric key that protects the key entry file
|
||||
*/
|
||||
public KeyPair loadKeyPair(KeyEntry keyEntry, SecretKey secretKey) {
|
||||
FileUtil.rollingBackup(storageDir, keyEntry.getFileName() + ".key", 20);
|
||||
try {
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(keyEntry.getAlgorithm());
|
||||
byte[] encodedPrivateKey = loadKeyBytes(keyEntry, secretKey);
|
||||
|
|
|
@ -74,6 +74,19 @@ public class FileUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static void deleteRollingBackup(File dir, String fileName) {
|
||||
File backupDir = new File(Paths.get(dir.getAbsolutePath(), "backup").toString());
|
||||
if (!backupDir.exists()) throw new RuntimeException("backup directory does not exist: " + backupDir);
|
||||
String dirName = "backups_" + fileName;
|
||||
if (dirName.contains(".")) dirName = dirName.replace(".", "_");
|
||||
File backupFileDir = new File(Paths.get(backupDir.getAbsolutePath(), dirName).toString());
|
||||
try {
|
||||
FileUtils.deleteDirectory(backupFileDir);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void pruneBackup(File backupDir, int numMaxBackupFiles) {
|
||||
if (backupDir.isDirectory()) {
|
||||
File[] files = backupDir.listFiles();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue