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 <waitstory@163.com>

* Fixed an error when using the command to download src

issue: #2938

Signed-off-by: waitstory <waitstory@163.com>

---------

Signed-off-by: waitstory <waitstory@163.com>
This commit is contained in:
waitstory
2024-06-10 10:00:31 +05:30
committed by GitHub
parent ef05e242e4
commit 9b978cf2fd
+11 -19
View File
@@ -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
}