UpdateGoPath() (probably without memory corruption)
This commit is contained in:
parent
f1c2695662
commit
704d06ba87
|
@ -14,7 +14,7 @@ add:
|
|||
./forgeConfig --add --name 'foo' --gopath 'go.wit.com/apps/foo'
|
||||
|
||||
update:
|
||||
./forgeConfig --update --name 'foo' --gopath 'go.wit.com/apps/foonew'
|
||||
./forgeConfig --update --name 'foo' --gopath 'more stuff but not memory corruption?'
|
||||
|
||||
corruptMemory:
|
||||
./forgeConfig --update --name 'foo' --gopath 'blah'
|
||||
|
|
|
@ -23,25 +23,22 @@ func main() {
|
|||
loop := repos.SortByName() // get the list of repos
|
||||
for loop.Scan() {
|
||||
r := loop.Repo()
|
||||
log.Info("repo:", r.Name, r.Gopath)
|
||||
log.Info("repo:", r.Name, r.GoPath)
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
if argv.Update {
|
||||
r := repos.FindByName(argv.Name) // find the repo
|
||||
if r == nil {
|
||||
log.Info("rep:", argv.Name, "not found")
|
||||
os.Exit(-1)
|
||||
}
|
||||
r.Gopath = argv.GoPath
|
||||
if repos.UpdateGoPath(argv.Name, argv.GoPath) {
|
||||
// save updated config file
|
||||
repos.ConfigSave()
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
if argv.Add {
|
||||
log.Info("going to add a new repo", argv.Name, argv.GoPath)
|
||||
new1 := new(forgepb.Repo)
|
||||
new1.Name = argv.Name
|
||||
new1.Gopath = argv.GoPath
|
||||
new1.GoPath = argv.GoPath
|
||||
if repos.Append(new1) {
|
||||
log.Info("added", new1.Name, "ok")
|
||||
} else {
|
||||
|
|
|
@ -19,7 +19,7 @@ message Repo {
|
|||
bool readonly = 6; // if you have write access to the repo
|
||||
bool private = 7; // if the repo can be published
|
||||
string debname = 8; // this is the actual .deb name of the package
|
||||
string gopath = 9; // Examples: 'go.wit.com/apps/go-clone' or "~/mythings" or "/home/src/foo"
|
||||
string goPath = 9; // Examples: 'go.wit.com/apps/go-clone' or "~/mythings" or "/home/src/foo"
|
||||
google.protobuf.Timestamp verstamp = 10; // the git commit timestamp of the version
|
||||
}
|
||||
|
||||
|
|
17
repos.go
17
repos.go
|
@ -118,6 +118,23 @@ func (a ByRepoName) Len() int { return len(a) }
|
|||
func (a ByRepoName) Less(i, j int) bool { return a[i].Name < a[j].Name }
|
||||
func (a ByRepoName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
|
||||
func (all *Repos) DeleteByName(name string) *Repo {
|
||||
reposLock.Lock()
|
||||
defer reposLock.Unlock()
|
||||
|
||||
var newr Repo
|
||||
|
||||
for i, _ := range all.Repos {
|
||||
if all.Repos[i].Name == name {
|
||||
newr = *all.Repos[i]
|
||||
all.Repos[i] = all.Repos[len(all.Repos)-1]
|
||||
all.Repos = all.Repos[:len(all.Repos)-1]
|
||||
return &newr
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// safely returns a slice of pointers to the Repo protobufs
|
||||
func (r *Repos) selectAllRepos() []*Repo {
|
||||
reposLock.RLock()
|
||||
|
|
18
update.go
18
update.go
|
@ -1,11 +1,13 @@
|
|||
package forgepb
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func (repos *Repos) UpdateGoPath(r *Repo, gopath string) {
|
||||
r.Gopath = gopath
|
||||
repos.ConfigSave()
|
||||
os.Exit(0)
|
||||
func (all *Repos) UpdateGoPath(name string, gopath string) bool {
|
||||
oldr := all.DeleteByName(name)
|
||||
if oldr == nil {
|
||||
// nothing to update
|
||||
return false
|
||||
}
|
||||
|
||||
// update gopath and append it back to the list
|
||||
oldr.GoPath = gopath
|
||||
return all.Append(oldr)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue