Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zheng <[email protected]>
  • Loading branch information
Two-Hearts committed Jan 5, 2024
1 parent 96570a6 commit 3e4f1b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions cmd/notation/internal/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func DownloadPluginFromURL(ctx context.Context, pluginURL, tmpDir string) (*os.F
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%s %q: https response bad status: %s", resp.Request.Method, resp.Request.URL, resp.Status)
}
// get the downloaded file name
var downloadedFilename string
if cd := resp.Header.Get("Content-Disposition"); cd != "" {
_, params, err := mime.ParseMediaType(cd)
Expand Down
15 changes: 8 additions & 7 deletions cmd/notation/plugin/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import (
)

const (
notationPluginTmpDir = "notation-plugin"
pluginDownloadTmpDir = "notation-plugin-download"
pluginDecompressTmpDir = "notation-plugin-decompress"
)

type pluginInstallOpts struct {
Expand Down Expand Up @@ -135,7 +136,7 @@ func install(command *cobra.Command, opts *pluginInstallOpts) error {
if pluginURL.Scheme != "https" {
return fmt.Errorf("failed to download plugin from URL: only the HTTPS scheme is supported, but got %s", pluginURL.Scheme)
}
tmpDir, err := os.MkdirTemp("", notationPluginTmpDir)
tmpDir, err := os.MkdirTemp("", pluginDownloadTmpDir)
if err != nil {
return fmt.Errorf("failed to create temporary directory: %w", err)
}
Expand Down Expand Up @@ -198,9 +199,9 @@ func installPlugin(ctx context.Context, inputPath string, inputChecksum string,
if inputFileInfo.Size() >= osutil.MaxFileBytes {
return fmt.Errorf("file size reached the %d MiB size limit", osutil.MaxFileBytes/1024/1024)
}
// set permission to 0700 for plugin validation before installation.
// The eventual plugin permission is updated in notation-go.
if err := os.Chmod(inputPath, 0700); err != nil {
// set permission for plugin validation before installation.
// The eventual plugin permission is determined in notation-go.
if err := os.Chmod(inputPath, inputFileInfo.Mode()|os.FileMode(0700)); err != nil {
return err
}
installOpts := plugin.CLIInstallOptions{
Expand All @@ -220,7 +221,7 @@ func installPluginFromFS(ctx context.Context, pluginFS fs.FS, force bool) error
logger := log.GetLogger(ctx)
root := "."
// extracting all regular files from root into tmpDir
tmpDir, err := os.MkdirTemp("", notationPluginTmpDir)
tmpDir, err := os.MkdirTemp("", pluginDecompressTmpDir)
if err != nil {
return fmt.Errorf("failed to create temporary directory: %w", err)
}
Expand Down Expand Up @@ -282,7 +283,7 @@ func installPluginFromTarGz(ctx context.Context, tarGzPath string, force bool) e
defer decompressedStream.Close()
tarReader := tar.NewReader(decompressedStream)
// extracting all regular files into tmpDir
tmpDir, err := os.MkdirTemp("", notationPluginTmpDir)
tmpDir, err := os.MkdirTemp("", pluginDecompressTmpDir)
if err != nil {
return fmt.Errorf("failed to create temporary directory: %w", err)
}
Expand Down

0 comments on commit 3e4f1b2

Please sign in to comment.