this .proto might allow generic marshal recovery

This commit is contained in:
Jeff Carr 2024-12-04 15:36:49 -06:00
parent 4d221c5220
commit f98179971e
7 changed files with 70 additions and 101 deletions

View File

@ -5,7 +5,7 @@
# go install # go install
all: forgeConfig.pb.go vet all: goimports forgeConfig.pb.go uuid.pb.go vet
vet: vet:
@GO111MODULE=off go vet @GO111MODULE=off go vet
@ -27,3 +27,6 @@ clean:
forgeConfig.pb.go: forgeConfig.proto forgeConfig.pb.go: forgeConfig.proto
autogenpb --proto forgeConfig.proto autogenpb --proto forgeConfig.proto
uuid.pb.go: uuid.proto
autogenpb --proto uuid.proto

View File

@ -1,27 +1,23 @@
package forgepb package forgepb
/* /*
check settings for a particular gopath lookup settings for a particular *gitpb.Repo or gopath string
this provides checks for:
IsReadOnly() // user can't push commits user settings are configured in ~/.config/forge/forge.text
IsPrivate() // repo can't be published to the pkg.go.dev system
// searchs by string
Configs.IsReadOnly(path) // user can't push commits
Configs.IsWritable(path) // the opposite, but maybe different so I put both here
IsPrivate(repo) // repo can't be published to the pkg.go.dev system
DebName() // for 'zookeeper' returns 'zookeeper-go' DebName() // for 'zookeeper' returns 'zookeeper-go'
*/ */
import ( import (
"path/filepath" "path/filepath"
"strings" "strings"
"go.wit.com/lib/protobuf/gitpb"
) )
/*
func (f *Forge) SortByGoPath() *ForgeConfigIterator {
return f.Config.SortByPath()
}
*/
/* /*
func (all *ForgeConfigs) UpdateGoPath(name string, gopath string) bool { func (all *ForgeConfigs) UpdateGoPath(name string, gopath string) bool {
oldr := all.DeleteByGoPath(name) oldr := all.DeleteByGoPath(name)
@ -38,19 +34,10 @@ func (all *ForgeConfigs) UpdateGoPath(name string, gopath string) bool {
// returns true if gopath is readonly() // returns true if gopath is readonly()
// will attempt to match IsWritable("foo") against anything ending in "foo" // will attempt to match IsWritable("foo") against anything ending in "foo"
func (f *Forge) IsReadOnly(repo *gitpb.Repo) bool { func (fc *ForgeConfigs) IsReadOnly(gopath string) bool {
// var match *ForgeConfig
return f.Config.IsReadOnly(repo.GoPath)
}
// returns true if gopath is readonly()
// will attempt to match IsWritable("foo") against anything ending in "foo"
func (f *ForgeConfigs) IsReadOnly(gopath string) bool {
var match *ForgeConfig var match *ForgeConfig
loop := fc.SortByGoPath() // get the list of repos
loop := f.SortByGoPath() // get the list of repos
for loop.Scan() { for loop.Scan() {
r := loop.Next() r := loop.Next()
if r.GoPath == gopath { if r.GoPath == gopath {
@ -107,11 +94,11 @@ func (f *ForgeConfigs) IsReadOnly(gopath string) bool {
// this let's you check a git tag version against a package .deb version // this let's you check a git tag version against a package .deb version
// allows gopath's to not need to match the .deb name // allows gopath's to not need to match the .deb name
// this is important in lots of cases! It is normal and happens often enough. // this is important in lots of cases! It is normal and happens often enough.
func (f *Forge) DebName(gopath string) string { func (fc *ForgeConfigs) DebName(gopath string) string {
// get "zookeeper" from "go.wit.com/apps/zookeeper" // get "zookeeper" from "go.wit.com/apps/zookeeper"
normalBase := filepath.Base(gopath) normalBase := filepath.Base(gopath)
loop := f.Config.SortByGoPath() loop := fc.SortByGoPath()
for loop.Scan() { for loop.Scan() {
r := loop.Next() r := loop.Next()
if r.GoPath == gopath { if r.GoPath == gopath {
@ -134,13 +121,13 @@ func (f *Forge) DebName(gopath string) string {
// //
// IsPrivate("go.foo.com/jcarr/foo") returns true if private // IsPrivate("go.foo.com/jcarr/foo") returns true if private
// IsPrivate("foo") also returns true if "go.bar.com/jcarr/foo" is private // IsPrivate("foo") also returns true if "go.bar.com/jcarr/foo" is private
func (f *Forge) IsPrivate(thing string) bool { func (fc *ForgeConfigs) IsPrivate(thing string) bool {
var match *ForgeConfig var match *ForgeConfig
// sort by path means the simple 'match' logic // sort by path means the simple 'match' logic
// here works in the sense the last directory match // here works in the sense the last directory match
// is the one that is used // is the one that is used
loop := f.Config.SortByGoPath() // get the list of repos loop := fc.SortByGoPath() // get the list of repos
for loop.Scan() { for loop.Scan() {
r := loop.Next() r := loop.Next()
if r.GoPath == thing { if r.GoPath == thing {
@ -178,10 +165,10 @@ func (f *Forge) IsPrivate(thing string) bool {
// file that lets you set things as favorites // file that lets you set things as favorites
// so you can just go-clone a bunch of common things // so you can just go-clone a bunch of common things
// on a new box or after you reset/delete your ~/go/src dir // on a new box or after you reset/delete your ~/go/src dir
func (f *Forge) IsFavorite(thing string) bool { func (fc *ForgeConfigs) IsFavorite(thing string) bool {
var match *ForgeConfig var match *ForgeConfig
loop := f.Config.SortByGoPath() // get the list of repos loop := fc.SortByGoPath() // get the list of repos
for loop.Scan() { for loop.Scan() {
r := loop.Next() r := loop.Next()
if r.GoPath == thing { if r.GoPath == thing {
@ -207,3 +194,36 @@ func (f *Forge) IsFavorite(thing string) bool {
return match.Favorite return match.Favorite
} }
// IsWritable() checks your .config/forge/ settings
// looks for an exact match, then
// looks for a directory match
func (fc *ForgeConfigs) IsWritable(thing string) bool {
var match *ForgeConfig
loop := fc.SortByGoPath() // get the list of repos
for loop.Scan() {
r := loop.Next()
if r.GoPath == thing {
if r.Writable {
return true
}
}
base := filepath.Base(r.GoPath)
if base == thing {
if r.Writable {
return true
}
}
if r.Directory {
if strings.HasPrefix(thing, r.GoPath) {
match = r
}
}
}
if match == nil {
return false
}
return match.Writable
}

View File

@ -20,7 +20,7 @@ func (f *Forge) FinalGoDepsCheckOk(check *gitpb.Repo) bool {
log.Info("boo, check == nil") log.Info("boo, check == nil")
return false return false
} }
if ! check.Exists("go.mod") { if !check.Exists("go.mod") {
log.Info("go.mod is missing in", check.GoPath) log.Info("go.mod is missing in", check.GoPath)
return false return false
} }
@ -58,7 +58,7 @@ func (f *Forge) FinalGoDepsCheckOk(check *gitpb.Repo) bool {
// log.Info("found dep", depRepo.GetGoPath()) // log.Info("found dep", depRepo.GetGoPath())
if depRepo.GetVersion() != found.GetTargetVersion() { if depRepo.GetVersion() != found.GetTargetVersion() {
check := f.Repos.FindByGoPath(depRepo.GoPath) check := f.Repos.FindByGoPath(depRepo.GoPath)
if f.IsReadOnly(check) { if f.Config.IsReadOnly(check.GoPath) {
log.Printf("%-48s ok error .%s. vs .%s. (ignoring read-only repo)", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetTargetVersion()) log.Printf("%-48s ok error .%s. vs .%s. (ignoring read-only repo)", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetTargetVersion())
} else { } else {
if f.checkOverride(depRepo.GetGoPath()) { if f.checkOverride(depRepo.GetGoPath()) {

View File

@ -4,6 +4,8 @@ package forgepb;
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
// `autogenpb:uuid:7267f5d5-954b-44b7-9f67-2eb808791355` // todo: add file support
// define 3 branches. that is all that is supported // define 3 branches. that is all that is supported
// the term 'master' is used in the code because 'main' is a reserved word in golang already // the term 'master' is used in the code because 'main' is a reserved word in golang already
// allow 'read only' and 'private' flags // allow 'read only' and 'private' flags
@ -31,7 +33,6 @@ message ForgeConfig {
google.protobuf.Timestamp verstamp = 12; // the git commit timestamp of the version google.protobuf.Timestamp verstamp = 12; // the git commit timestamp of the version
} }
// TODO: autogen 'sort', 'marshal'
message ForgeConfigs { // `autogenpb:marshal` message ForgeConfigs { // `autogenpb:marshal`
string uuid = 1; // could be useful for /usr/share/file/magic someday? string uuid = 1; // could be useful for /usr/share/file/magic someday?
string version = 2; // could be used for protobuf schema change violations? string version = 2; // could be used for protobuf schema change violations?

View File

@ -23,10 +23,10 @@ func standardHeader() string {
func (f *Forge) standardHeader(r *ForgeConfig) string { func (f *Forge) standardHeader(r *ForgeConfig) string {
var flags string var flags string
var readonly string var readonly string
if f.IsPrivate(r.GoPath) { if f.Config.IsPrivate(r.GoPath) {
flags += "(private) " flags += "(private) "
} }
if f.IsFavorite(r.GoPath) { if f.Config.IsFavorite(r.GoPath) {
flags += "(favorite) " flags += "(favorite) "
} }
if f.Config.IsReadOnly(r.GoPath) { if f.Config.IsReadOnly(r.GoPath) {

View File

@ -13,71 +13,6 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
/*
// guess the paths. returns
// realpath : the actual path on the filesystem
// goSrcPath : this could be ~/go/src, or where the go.work file is
// goPath : go.wit.com/lib/gui/repostatus (for example)
// true/false if the repo is a golang repo
func (f *Forge) guessPaths(path string) (string, string, string, bool, error) {
var realpath, goSrcDir string
var isGoLang bool = false
homeDir, err := os.UserHomeDir()
if err != nil {
log.Log(FORGEPBWARN, "Error getting home directory:", err)
return path, realpath, goSrcDir, false, err
}
goSrcDir = filepath.Join(homeDir, "go/src")
// allow arbitrary paths, otherwise, assume the repo is in ~/go/src
// unless REPO_WORK_PATH was set. to over-ride ~/go/src
// todo, look for go.work
if os.Getenv("REPO_WORK_PATH") == "" {
os.Setenv("REPO_WORK_PATH", goSrcDir)
} else {
goSrcDir = os.Getenv("REPO_WORK_PATH")
}
// todo: this is dumb
if strings.HasPrefix(path, "/") {
realpath = path
} else if strings.HasPrefix(path, "~") {
tmp := strings.TrimPrefix(path, "~")
realpath = filepath.Join(homeDir, tmp)
} else {
realpath = filepath.Join(goSrcDir, path)
isGoLang = true
}
if os.Getenv("REPO_AUTO_CLONE") == "true" {
err := f.Clone(goSrcDir, path)
if err != nil {
// directory doesn't exist. exit with nil and error nil
return path, realpath, goSrcDir, false, errors.New("git clone")
}
}
if !IsDirectory(realpath) {
log.Log(FORGEPBWARN, "directory doesn't exist", realpath)
// directory doesn't exist. exit with nil and error nil
return path, realpath, goSrcDir, false, errors.New(realpath + " does not exist")
}
filename := filepath.Join(realpath, ".git/config")
_, err = os.Open(filename)
if err != nil {
// log.Log(WARN, "Error reading .git/config:", filename, err)
// log.Log(WARN, "TODO: find .git/config in parent directory")
return path, realpath, goSrcDir, false, err
}
return path, realpath, goSrcDir, isGoLang, nil
}
*/
// TODO: make some config file for things like this // TODO: make some config file for things like this
// can be used to work around temporary problems // can be used to work around temporary problems
func clonePathHack(dirname string, basedir string, gopath string) (string, error) { func clonePathHack(dirname string, basedir string, gopath string) (string, error) {

10
uuid.proto Normal file
View File

@ -0,0 +1,10 @@
syntax = "proto3";
// experiment to identify .pb files incase things go sideways
package forgepb;
// autogenpb:no-sort
message UuidConfigs { // `autogenpb:marshal`
string uuid = 1; // could be useful for /usr/share/file/magic someday?
string version = 2; // could be used for protobuf schema change violations?
}