Save the vault when saving group filter right after a vault version bump

This commit is contained in:
Alexander Bakker 2024-05-31 16:24:18 +02:00
parent 892116fcd7
commit 2b69dc3a84
3 changed files with 25 additions and 2 deletions

View File

@ -1047,6 +1047,9 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
@Override @Override
public void onSaveGroupFilter(Set<UUID> groupFilter) { public void onSaveGroupFilter(Set<UUID> groupFilter) {
if (_vaultManager.getVault().isGroupsMigrationFresh()) {
saveAndBackupVault();
}
_prefs.setGroupFilter(groupFilter); _prefs.setGroupFilter(groupFilter);
} }

View File

@ -16,6 +16,9 @@ public class Vault {
private final UUIDMap<VaultEntry> _entries = new UUIDMap<>(); private final UUIDMap<VaultEntry> _entries = new UUIDMap<>();
private final UUIDMap<VaultGroup> _groups = new UUIDMap<>(); private final UUIDMap<VaultGroup> _groups = new UUIDMap<>();
// Whether we've migrated the group list to the new format while parsing the vault
private boolean _isGroupsMigrationFresh = false;
public JSONObject toJson() { public JSONObject toJson() {
return toJson(null); return toJson(null);
} }
@ -70,7 +73,9 @@ public class Vault {
JSONArray array = obj.getJSONArray("entries"); JSONArray array = obj.getJSONArray("entries");
for (int i = 0; i < array.length(); i++) { for (int i = 0; i < array.length(); i++) {
VaultEntry entry = VaultEntry.fromJson(array.getJSONObject(i)); VaultEntry entry = VaultEntry.fromJson(array.getJSONObject(i));
vault.migrateOldGroup(entry); if (vault.migrateOldGroup(entry)) {
vault.setGroupsMigrationFresh();
}
// check the vault has a group corresponding to each one the entry claims to be in // check the vault has a group corresponding to each one the entry claims to be in
for (UUID groupUuid: entry.getGroups()) { for (UUID groupUuid: entry.getGroups()) {
@ -88,7 +93,15 @@ public class Vault {
return vault; return vault;
} }
public void migrateOldGroup(VaultEntry entry) { private void setGroupsMigrationFresh() {
_isGroupsMigrationFresh = true;
}
public boolean isGroupsMigrationFresh() {
return _isGroupsMigrationFresh;
}
public boolean migrateOldGroup(VaultEntry entry) {
if (entry.getOldGroup() != null) { if (entry.getOldGroup() != null) {
Optional<VaultGroup> optGroup = getGroups().getValues() Optional<VaultGroup> optGroup = getGroups().getValues()
.stream() .stream()
@ -104,7 +117,10 @@ public class Vault {
} }
entry.setOldGroup(null); entry.setOldGroup(null);
return true;
} }
return false;
} }
public UUIDMap<VaultEntry> getEntries() { public UUIDMap<VaultEntry> getEntries() {

View File

@ -314,6 +314,10 @@ public class VaultRepository {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public boolean isGroupsMigrationFresh() {
return _vault.isGroupsMigrationFresh();
}
public VaultFileCredentials getCredentials() { public VaultFileCredentials getCredentials() {
return _creds == null ? null : _creds.clone(); return _creds == null ? null : _creds.clone();
} }