From 9b978cf2fd88f6fab63db79d3d35e25efc9bce70 Mon Sep 17 00:00:00 2001 From: waitstory <1392579945@qq.com> Date: Mon, 10 Jun 2024 12:30:31 +0800 Subject: [PATCH] Fixed an error when using the command to download src (#2940) * Fixed an error when using the command to download src issue: #2938 Signed-off-by: waitstory * Fixed an error when using the command to download src issue: #2938 Signed-off-by: waitstory --------- Signed-off-by: waitstory --- pkg/fission-cli/cmd/package/util/util.go | 30 +++++++++--------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/pkg/fission-cli/cmd/package/util/util.go b/pkg/fission-cli/cmd/package/util/util.go index b2b96d7d..f1e15802 100644 --- a/pkg/fission-cli/cmd/package/util/util.go +++ b/pkg/fission-cli/cmd/package/util/util.go @@ -195,29 +195,21 @@ func DownloadStrorageURL(ctx context.Context, client cmd.Client, fileUrl string) } func WriteArchiveToFile(fileName string, reader io.Reader) error { - tmpDir, err := utils.GetTempDir() + // Create the target file directly + file, err := os.Create(fileName) + if err != nil { + return err + } + defer file.Close() + + // Copy data from the reader to the target file + _, err = io.Copy(file, reader) if err != nil { return err } - tmpFileName := uuid.NewString() - - path := filepath.Join(tmpDir, tmpFileName+".tmp") - w, err := os.Create(path) - if err != nil { - return err - } - defer w.Close() - _, err = io.Copy(w, reader) - if err != nil { - return err - } - err = os.Chmod(path, 0644) - if err != nil { - return err - } - - err = os.Rename(path, fileName) + // Change the permissions of the target file + err = os.Chmod(fileName, 0644) if err != nil { return err }