Match saved bookmarks against existing collections and remove missing

This commit is contained in:
2025-10-28 11:38:41 +01:00
parent 16682b8539
commit 3a17961c5c

View File

@@ -44,6 +44,38 @@ public class PasswordStoreService : IPasswordStoreService
public IEnumerable<PasswordStore> GetAll() public IEnumerable<PasswordStore> GetAll()
{ {
return repository.GetAll(); List<PasswordStore> jsonResults = repository.GetAll();
//Validate against actual secret collections
var collections = secretService.GetCollections() ?? Enumerable.Empty<Secret.Collection>();
// Identify bookmarks that do NOT match any existing Secret collection.
var toDelete = new List<uint>();
foreach (var ps in jsonResults)
{
var key = string.IsNullOrWhiteSpace(ps.DisplayName) ? ps.Path : ps.DisplayName;
if (string.IsNullOrWhiteSpace(key))
{
// No reasonable key to match — schedule for deletion
toDelete.Add(ps.ID);
continue;
}
var exists = collections.Any(c => string.Equals(c.Label, key, StringComparison.OrdinalIgnoreCase));
if (!exists)
{
toDelete.Add(ps.ID);
}
}
// Perform deletions from repository for all missing bookmarks
foreach (var id in toDelete)
{
repository.Delete(id);
}
var remaining = jsonResults.Where(ps => !toDelete.Contains(ps.ID)).ToList();
return remaining;
} }
} }