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 (
"archive/zip"
"bufio"
"crypto/sha256"
"embed"
"errors"
"fmt"
@ -112,10 +113,20 @@ func CopyEmbed(efs embed.FS) error {
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
})