diff options
| author | Jeff Carr <[email protected]> | 2025-11-02 08:58:17 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-11-02 08:58:17 -0600 |
| commit | d5da48e0f80f4a5114ed906bdb8689f5ff5d4ac9 (patch) | |
| tree | d2d0df927773da30966cb9b67d95b6533c70e085 | |
| parent | d8ad8ed5a7d294d19185ca1bc54039e1184831ba (diff) | |
add a function to force create the PB on errdevel
| -rw-r--r-- | cacheDir.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/cacheDir.go b/cacheDir.go index 2804f9e..b7c1c00 100644 --- a/cacheDir.go +++ b/cacheDir.go @@ -17,6 +17,7 @@ import ( "os" "go.wit.com/lib/env" + "go.wit.com/lib/protobuf/filepb" "google.golang.org/protobuf/proto" ) @@ -97,3 +98,41 @@ func ForceCreateCacheDirPB(pb proto.Message, dirname string, filename string) er err = SaveToFilename(pb, fullname) return err } + +// checks the UUID and Version of the .pb file +// should re-create the file with the new .proto (unless the filename is bank) +func ForceCreatePB(pb proto.Message) error { + fullname, err := GetFilename(pb) + if err != nil { + // fmt.Println(fullname, "err", err) + return err + } + + if fullname == "" { + // fmt.Println(fullname, "is blank") + return errors.New("filename PB is blank") + } + + newver, curver, err := filepb.VersionCheckFile(pb, fullname) + _, _ = newver, curver + if err == nil { + // everything is fine. Versions match. load file + err = LoadFromFilename(pb, fullname) + if err == nil { + // fmt.Println(fullname, "should have worked") + return nil + } + fmt.Printf("lib/config Load() %s failed. Removing file. (%v)\n", fullname, err) + } + if !errors.Is(err, os.ErrNotExist) { + // Version Check failed. + err = os.Remove(fullname) + if err != nil { + fmt.Printf("lib/config os.Remove() %s failed (%v)\n", fullname, err) + } + } + // if there is any err, recreate the file + err = SaveToFilename(pb, fullname) + fmt.Printf("lib/config Saved new cache file (%s)\n", fullname) + return err +} |
