diff --git a/cmd/joj3/conf/conf.go b/cmd/joj3/conf/conf.go index bba1b4d..dd29123 100644 --- a/cmd/joj3/conf/conf.go +++ b/cmd/joj3/conf/conf.go @@ -1,7 +1,10 @@ package conf import ( + "crypto/sha256" + "encoding/hex" "fmt" + "io" "log/slog" "os" "path/filepath" @@ -195,6 +198,23 @@ func ParseConfFile(path string) (conf *Conf, err error) { return } +func GetSHA256(filePath string) (string, error) { + // Open the file + file, err := os.Open(filePath) + if err != nil { + return "", err + } + defer file.Close() + + // Calculate SHA-256 + hash := sha256.New() + if _, err := io.Copy(hash, file); err != nil { + return "", err + } + + return hex.EncodeToString(hash.Sum(nil)), nil +} + func ParseMsg(confRoot, confName, msg, tag string) (confPath, group string, err error) { slog.Info("parse msg", "msg", msg) conventionalCommit, err := parseConventionalCommit(msg) diff --git a/cmd/joj3/main.go b/cmd/joj3/main.go index 6d1c2b4..e065db8 100644 --- a/cmd/joj3/main.go +++ b/cmd/joj3/main.go @@ -52,12 +52,22 @@ func mainImpl() error { return err } slog.Info("try to load conf", "path", confPath) + confStat, err := os.Stat(confPath) + if err != nil { + if os.IsNotExist(err) { + conf.HintValidScopes(confRoot, confName) + } + slog.Error("stat conf", "error", err) + return err + } + sha256, err := conf.GetSHA256(confPath) + if err != nil { + slog.Error("get sha256", "error", err) + return err + } confObj, err := conf.ParseConfFile(confPath) if err != nil { slog.Error("parse conf", "error", err) - if _, statErr := os.Stat(confPath); os.IsNotExist(statErr) { - conf.HintValidScopes(confRoot, confName) - } return err } slog.Debug("conf loaded", "conf", confObj) @@ -65,6 +75,8 @@ func mainImpl() error { slog.Error("setup slog", "error", err) return err } + slog.Info("conf info", "sha256", sha256, "modTime", confStat.ModTime(), + "size", confStat.Size()) if err := conf.CheckExpire(confObj); err != nil { slog.Error("conf check expire", "error", err) return err