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'
|
./forgeConfig --add --name 'foo' --gopath 'go.wit.com/apps/foo'
|
||||||
|
|
||||||
update:
|
update:
|
||||||
./forgeConfig --update --name 'foo' --gopath 'go.wit.com/apps/foonew'
|
./forgeConfig --update --name 'foo' --gopath 'more stuff but not memory corruption?'
|
||||||
|
|
||||||
corruptMemory:
|
corruptMemory:
|
||||||
./forgeConfig --update --name 'foo' --gopath 'blah'
|
./forgeConfig --update --name 'foo' --gopath 'blah'
|
||||||
|
|
|
@ -23,25 +23,22 @@ func main() {
|
||||||
loop := repos.SortByName() // get the list of repos
|
loop := repos.SortByName() // get the list of repos
|
||||||
for loop.Scan() {
|
for loop.Scan() {
|
||||||
r := loop.Repo()
|
r := loop.Repo()
|
||||||
log.Info("repo:", r.Name, r.Gopath)
|
log.Info("repo:", r.Name, r.GoPath)
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
if argv.Update {
|
if argv.Update {
|
||||||
r := repos.FindByName(argv.Name) // find the repo
|
if repos.UpdateGoPath(argv.Name, argv.GoPath) {
|
||||||
if r == nil {
|
// save updated config file
|
||||||
log.Info("rep:", argv.Name, "not found")
|
repos.ConfigSave()
|
||||||
os.Exit(-1)
|
|
||||||
}
|
}
|
||||||
r.Gopath = argv.GoPath
|
|
||||||
repos.ConfigSave()
|
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
if argv.Add {
|
if argv.Add {
|
||||||
log.Info("going to add a new repo", argv.Name, argv.GoPath)
|
log.Info("going to add a new repo", argv.Name, argv.GoPath)
|
||||||
new1 := new(forgepb.Repo)
|
new1 := new(forgepb.Repo)
|
||||||
new1.Name = argv.Name
|
new1.Name = argv.Name
|
||||||
new1.Gopath = argv.GoPath
|
new1.GoPath = argv.GoPath
|
||||||
if repos.Append(new1) {
|
if repos.Append(new1) {
|
||||||
log.Info("added", new1.Name, "ok")
|
log.Info("added", new1.Name, "ok")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -19,7 +19,7 @@ message Repo {
|
||||||
bool readonly = 6; // if you have write access to the repo
|
bool readonly = 6; // if you have write access to the repo
|
||||||
bool private = 7; // if the repo can be published
|
bool private = 7; // if the repo can be published
|
||||||
string debname = 8; // this is the actual .deb name of the package
|
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
|
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) 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 (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
|
// safely returns a slice of pointers to the Repo protobufs
|
||||||
func (r *Repos) selectAllRepos() []*Repo {
|
func (r *Repos) selectAllRepos() []*Repo {
|
||||||
reposLock.RLock()
|
reposLock.RLock()
|
||||||
|
|
16
update.go
16
update.go
|
@ -1,11 +1,13 @@
|
||||||
package forgepb
|
package forgepb
|
||||||
|
|
||||||
import (
|
func (all *Repos) UpdateGoPath(name string, gopath string) bool {
|
||||||
"os"
|
oldr := all.DeleteByName(name)
|
||||||
)
|
if oldr == nil {
|
||||||
|
// nothing to update
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (repos *Repos) UpdateGoPath(r *Repo, gopath string) {
|
// update gopath and append it back to the list
|
||||||
r.Gopath = gopath
|
oldr.GoPath = gopath
|
||||||
repos.ConfigSave()
|
return all.Append(oldr)
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue