fix: 解决升级失败的问题 (#4419)

pull/4420/head
ssongliu 2024-04-07 22:09:46 +08:00 committed by GitHub
parent 62828c464e
commit 7c9608727d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 4 deletions

View File

@ -94,14 +94,16 @@ func CopyFile(src, dst string) error {
if path.Base(src) != path.Base(dst) {
dst = path.Join(dst, path.Base(src))
}
dest, err := os.Create(dst)
target, err := os.OpenFile(dst+"_temp", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
if err != nil {
return err
}
defer dest.Close()
defer target.Close()
_, err = io.Copy(dest, source)
if err != nil {
if _, err = io.Copy(target, source); err != nil {
return err
}
if err = os.Rename(dst+"_temp", dst); err != nil {
return err
}
return nil