Skip to content

Commit a7e81cf

Browse files
committed
plaintextstore: do not write creds if nothing has changed
Do not needlessly serialise the credential file again if nothing has changed from an existing credential found. This change also updates derived implementations (DPAPI and GPG).
1 parent 58556d3 commit a7e81cf

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/shared/Core/PlaintextCredentialStore.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ public void AddOrUpdate(string service, string account, string secret)
3333
// Ensure the store root exists and permissions are set
3434
EnsureStoreRoot();
3535

36+
FileCredential existingCredential = Enumerate(service, account).FirstOrDefault();
37+
38+
// No need to update existing credential if nothing has changed
39+
if (existingCredential != null &&
40+
StringComparer.Ordinal.Equals(account, existingCredential.Account) &&
41+
StringComparer.Ordinal.Equals(secret, existingCredential.Password))
42+
{
43+
return;
44+
}
45+
3646
string serviceSlug = CreateServiceSlug(service);
3747
string servicePath = Path.Combine(StoreRoot, serviceSlug);
3848

0 commit comments

Comments
 (0)