Skip to content

Commit

Permalink
Revert changes to buf plugin update
Browse files Browse the repository at this point in the history
  • Loading branch information
doriable committed Dec 9, 2024
1 parent 1c8e6fa commit 7b48937
Showing 1 changed file with 1 addition and 28 deletions.
29 changes: 1 addition & 28 deletions private/buf/cmd/buf/command/plugin/pluginupdate/pluginupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ import (
"context"
"errors"
"fmt"
"sort"

"github.com/bufbuild/buf/private/buf/bufcli"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/app/appcmd"
"github.com/bufbuild/buf/private/pkg/app/appext"
"github.com/bufbuild/buf/private/pkg/slicesext"
"github.com/bufbuild/buf/private/pkg/syserror"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -133,31 +131,6 @@ func run(
if err != nil {
return err
}
// We do not prune the buf.lock during update, we only add update existing plugin keys
// or add new plugin keys.
configuredRemotePluginKeyNameToPluginKey := map[string]bufplugin.PluginKey{}
for _, configuredRemotePluginKey := range configuredRemotePluginKeys {
configuredRemotePluginKeyNameToPluginKey[configuredRemotePluginKey.FullName().String()] = configuredRemotePluginKey
}
var updatedRemotePluginKeys []bufplugin.PluginKey
for _, existingRemotePluginKey := range existingRemotePluginKeys {
if updatedRemotePluginKey, ok := configuredRemotePluginKeyNameToPluginKey[existingRemotePluginKey.FullName().String()]; ok {
updatedRemotePluginKeys = append(updatedRemotePluginKeys, updatedRemotePluginKey)
// This was found and updated, so we can delete from the map
delete(configuredRemotePluginKeyNameToPluginKey, existingRemotePluginKey.FullName().String())
} else {
// Otherwise, keep the existing remote plugin key from buf.lock
updatedRemotePluginKeys = append(updatedRemotePluginKeys, existingRemotePluginKey)
}
}
// Add any new configured remote plugin keys
updatedRemotePluginKeys = append(updatedRemotePluginKeys, slicesext.MapValuesToSlice(configuredRemotePluginKeyNameToPluginKey)...)
sort.Slice(
updatedRemotePluginKeys,
func(i int, j int) bool {
return updatedRemotePluginKeys[i].FullName().String() < updatedRemotePluginKeys[j].FullName().String()
},
)

// We're about to edit the buf.lock file on disk. If we have a subsequent error,
// attempt to revert the buf.lock file.
Expand All @@ -171,7 +144,7 @@ func run(
}
}()
// Edit the buf.lock file with the updated remote plugins.
if err := workspaceDepManager.UpdateBufLockFile(ctx, existingDepModuleKeys, updatedRemotePluginKeys); err != nil {
if err := workspaceDepManager.UpdateBufLockFile(ctx, existingDepModuleKeys, configuredRemotePluginKeys); err != nil {
return err
}
return nil
Expand Down

0 comments on commit 7b48937

Please sign in to comment.