Skip to content

Commit 5f067ac

Browse files
authored
fix(plugin): don't remove plugins when updating index.yaml file (#9358)
1 parent 6e99dd3 commit 5f067ac

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pkg/plugin/index.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"errors"
77
"fmt"
8+
"io/fs"
89
"os"
910
"path/filepath"
1011
"strings"
@@ -34,10 +35,23 @@ type Index struct {
3435

3536
func (m *Manager) Update(ctx context.Context, opts Options) error {
3637
m.logger.InfoContext(ctx, "Updating the plugin index...", log.String("url", m.indexURL))
37-
if _, err := downloader.Download(ctx, m.indexURL, filepath.Dir(m.indexPath), "",
38-
downloader.Options{Insecure: opts.Insecure}); err != nil {
38+
39+
// Download the index file to a temporary directory and copy it to the plugins directory,
40+
// to avoid removing installed plugins.
41+
tempDir, err := downloader.DownloadToTempDir(ctx, m.indexURL, downloader.Options{Insecure: opts.Insecure})
42+
if err != nil {
3943
return xerrors.Errorf("unable to download the plugin index: %w", err)
4044
}
45+
46+
err = os.MkdirAll(filepath.Dir(m.indexPath), fs.ModePerm)
47+
if err != nil {
48+
return xerrors.Errorf("failed to create plugin index dir: %w", err)
49+
}
50+
51+
_, err = fsutils.CopyFile(filepath.Join(tempDir, "index.yaml"), m.indexPath)
52+
if err != nil {
53+
return xerrors.Errorf("unable to copy the plugin index file: %w", err)
54+
}
4155
return nil
4256
}
4357

0 commit comments

Comments
 (0)