From b988694da72e1f69f709ba0117b93862bcc3e1c9 Mon Sep 17 00:00:00 2001 From: josc146 Date: Fri, 22 Dec 2023 12:47:26 +0800 Subject: [PATCH] better CopyEmbed --- backend-golang/utils.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/backend-golang/utils.go b/backend-golang/utils.go index 731de3a..a003b63 100644 --- a/backend-golang/utils.go +++ b/backend-golang/utils.go @@ -3,6 +3,7 @@ package backend_golang import ( "archive/zip" "bufio" + "crypto/sha256" "embed" "errors" "fmt" @@ -112,9 +113,19 @@ func CopyEmbed(efs embed.FS) error { return err } - err = os.WriteFile(path, content, 0644) - if err != nil { - return err + executeWrite := true + existedContent, err := os.ReadFile(path) + 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