Skip to content

Commit

Permalink
Avoid skipping a storage due to identical string representations
Browse files Browse the repository at this point in the history
fmt.Sprintf("%v", thing) will use a fmt.Stringer implementation in thing, which means
that we cannot easily assume that this value is going to be unique here and can be used
to deduplicate the storages.

Instead: Use a `map[interface{}]struct{}` as we anyways have an interface, and interfaces
are perfectly fine map keys.
  • Loading branch information
ankon committed Nov 9, 2023
1 parent 3b3d678 commit d48d524
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions modules/caddytls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,28 +570,26 @@ func (t *TLS) cleanStorageUnits() {
}

// avoid cleaning same storage more than once per cleaning cycle
storagesCleaned := make(map[string]struct{})
storagesCleaned := make(map[interface{}]struct{})

// start with the default/global storage
storage := t.ctx.Storage()
storageStr := fmt.Sprintf("%v", storage)
t.logger.Info("cleaning storage unit", zap.String("description", storageStr))
t.logger.Info("cleaning storage unit", zap.Any("description", storage))
certmagic.CleanStorage(t.ctx, storage, options)
storagesCleaned[storageStr] = struct{}{}
storagesCleaned[storage] = struct{}{}

// then clean each storage defined in ACME automation policies
if t.Automation != nil {
for _, ap := range t.Automation.Policies {
if ap.storage == nil {
continue
}
storageStr := fmt.Sprintf("%v", ap.storage)
if _, ok := storagesCleaned[storageStr]; ok {
if _, ok := storagesCleaned[storage]; ok {
continue
}
t.logger.Info("cleaning storage unit", zap.String("description", storageStr))
t.logger.Info("cleaning storage unit", zap.Any("description", storage))
certmagic.CleanStorage(t.ctx, ap.storage, options)
storagesCleaned[storageStr] = struct{}{}
storagesCleaned[storage] = struct{}{}
}
}

Expand Down

0 comments on commit d48d524

Please sign in to comment.