File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,10 @@ func NewFileStore(file store) Store {
3030
3131// Erase removes the given credentials from the file store.
3232func (c * fileStore ) Erase (serverAddress string ) error {
33+ if _ , exists := c .file .GetAuthConfigs ()[serverAddress ]; ! exists {
34+ // nothing to do; no credentials found for the given serverAddress
35+ return nil
36+ }
3337 delete (c .file .GetAuthConfigs (), serverAddress )
3438 return c .file .Save ()
3539}
@@ -70,9 +74,14 @@ https://docs.docker.com/go/credential-store/
7074// CLI invocation (no need to warn the user multiple times per command).
7175var alreadyPrinted atomic.Bool
7276
73- // Store saves the given credentials in the file store.
77+ // Store saves the given credentials in the file store. This function is
78+ // idempotent and does not update the file if credentials did not change.
7479func (c * fileStore ) Store (authConfig types.AuthConfig ) error {
7580 authConfigs := c .file .GetAuthConfigs ()
81+ if oldAuthConfig , ok := authConfigs [authConfig .ServerAddress ]; ok && oldAuthConfig == authConfig {
82+ // Credentials didn't change, so skip updating the configuration file.
83+ return nil
84+ }
7685 authConfigs [authConfig .ServerAddress ] = authConfig
7786 if err := c .file .Save (); err != nil {
7887 return err
You can’t perform that action at this time.
0 commit comments