better CopyEmbed

This commit is contained in:
josc146 2023-12-22 12:47:26 +08:00
parent 512c4d0f73
commit b988694da7

View File

@ -3,6 +3,7 @@ package backend_golang
import ( import (
"archive/zip" "archive/zip"
"bufio" "bufio"
"crypto/sha256"
"embed" "embed"
"errors" "errors"
"fmt" "fmt"
@ -112,9 +113,19 @@ func CopyEmbed(efs embed.FS) error {
return err return err
} }
err = os.WriteFile(path, content, 0644) executeWrite := true
if err != nil { existedContent, err := os.ReadFile(path)
return err if err == nil {
if fmt.Sprintf("%x", sha256.Sum256(existedContent)) == fmt.Sprintf("%x", sha256.Sum256(content)) {
executeWrite = false
}
}
if executeWrite {
err = os.WriteFile(path, content, 0644)
if err != nil {
return err
}
} }
return nil return nil