Correctly handle key removal on Windows
filepath.Separator was platform dependent while storage.List does
already normalize returned paths.
Fixes
RELEASE_NOTES=[BUGFIX] Correctly handle key removal on Windows
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
+ "path"
"path/filepath"
"strings"
@@ -276,8 +277,18 @@ func (s *Store) UpdateExportedPublicKeys(ctx context.Context, rs []string) (bool
debug.Log("Checking %q for extra keys that need to be removed", keys)
for _, key := range keys {
- key := strings.TrimPrefix(key, keyDir+string(filepath.Separator))
- if !recipients[key] {
+ // do not use filepath, that would break on Windows. storage.List normalizes all paths
+ // returned to normal (forward) slashes. Even on Windows.
+ key := path.Base(key)
+
+ if recipients[key] {
+ debug.Log("Key %s found. Not removing", key)
+
+ continue
+ }
+
+ debug.Log("Remvoing extra key %s", key)
+
if err := s.storage.Delete(ctx, filepath.Join(keyDir, key)); err != nil {
out.Errorf(ctx, "Failed to remove extra key %q: %s", key, err)
@@ -294,7 +305,6 @@ func (s *Store) UpdateExportedPublicKeys(ctx context.Context, rs []string) (bool
exported = true
debug.Log("Removed extra key %s", key)
}
- }
if exported {
if err := s.storage.Commit(ctx, fmt.Sprintf("Updated exported Public Keys")); err != nil && !errors.Is(err, store.ErrGitNothingToCommit) {
