mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 21:36:45 +00:00
delay wallet file deletion to allow for database compaction and show error on failure
This commit is contained in:
parent
6481d83b0c
commit
7863fb7632
3 changed files with 37 additions and 4 deletions
|
@ -1905,7 +1905,22 @@ public class AppController implements Initializable {
|
|||
|
||||
private void deleteStorage(Storage storage) {
|
||||
if(storage.isClosed()) {
|
||||
Platform.runLater(storage::delete);
|
||||
Platform.runLater(() -> {
|
||||
Storage.DeleteWalletService deleteWalletService = new Storage.DeleteWalletService(storage);
|
||||
deleteWalletService.setDelay(Duration.seconds(3));
|
||||
deleteWalletService.setPeriod(Duration.hours(1));
|
||||
deleteWalletService.setOnSucceeded(event -> {
|
||||
deleteWalletService.cancel();
|
||||
if(!deleteWalletService.getValue()) {
|
||||
showErrorDialog("Error deleting wallet", "Could not delete " + storage.getWalletFile().getName() + ". Please delete this file manually.");
|
||||
}
|
||||
});
|
||||
deleteWalletService.setOnFailed(event -> {
|
||||
deleteWalletService.cancel();
|
||||
showErrorDialog("Error deleting wallet", "Could not delete " + storage.getWalletFile().getName() + ". Please delete this file manually.");
|
||||
});
|
||||
deleteWalletService.start();
|
||||
});
|
||||
} else {
|
||||
Platform.runLater(() -> deleteStorage(storage));
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ public class IOUtils {
|
|||
pos += data.length;
|
||||
}
|
||||
} catch(IOException e) {
|
||||
log.warn("Error overwriting file for deletion " + file.getName(), e);
|
||||
log.warn("Error overwriting file for deletion: " + file.getName(), e);
|
||||
}
|
||||
|
||||
return file.delete();
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.sparrowwallet.sparrow.AppServices;
|
|||
import com.sparrowwallet.sparrow.SparrowWallet;
|
||||
import com.sparrowwallet.sparrow.soroban.Soroban;
|
||||
import com.sparrowwallet.sparrow.whirlpool.Whirlpool;
|
||||
import javafx.concurrent.ScheduledService;
|
||||
import javafx.concurrent.Service;
|
||||
import javafx.concurrent.Task;
|
||||
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
||||
|
@ -263,9 +264,9 @@ public class Storage {
|
|||
persistence.copyWallet(walletFile, outputStream);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
public boolean delete() {
|
||||
deleteBackups();
|
||||
IOUtils.secureDelete(walletFile);
|
||||
return IOUtils.secureDelete(walletFile);
|
||||
}
|
||||
|
||||
public void deleteBackups() {
|
||||
|
@ -732,4 +733,21 @@ public class Storage {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class DeleteWalletService extends ScheduledService<Boolean> {
|
||||
private final Storage storage;
|
||||
|
||||
public DeleteWalletService(Storage storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Task<Boolean> createTask() {
|
||||
return new Task<>() {
|
||||
protected Boolean call() {
|
||||
return storage.delete();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue