Move name parsing logic to GetByName method

This commit is contained in:
Michael Crosby 2013-10-23 15:21:28 -07:00 committed by Victor Vieux
parent 7d440f70fd
commit 7c882a8003
2 changed files with 6 additions and 8 deletions

View File

@ -103,8 +103,7 @@ func (db *Database) Set(fullPath, id string) (*Entity, error) {
rollback := func() {
db.conn.Exec("ROLLBACK")
}
// FIXME: use exclusive transactions to avoid race conditions
if _, err := db.conn.Exec("BEGIN"); err != nil {
if _, err := db.conn.Exec("BEGIN EXCLUSIVE"); err != nil {
return nil, err
}
var entityId string

View File

@ -62,9 +62,6 @@ func (runtime *Runtime) getContainerElement(id string) *list.Element {
// Get looks for a container by the specified ID or name, and returns it.
// If the container is not found, or if an error occurs, nil is returned.
func (runtime *Runtime) Get(name string) *Container {
if name[0] != '/' {
name = "/" + name
}
if c, _ := runtime.GetByName(name); c != nil {
return c
}
@ -478,6 +475,10 @@ func (runtime *Runtime) Commit(container *Container, repository, tag, comment, a
}
func (runtime *Runtime) GetByName(name string) (*Container, error) {
if name[0] != '/' {
name = "/" + name
}
if id, err := runtime.idIndex.Get(name); err == nil {
name = id
}
@ -544,9 +545,7 @@ func (runtime *Runtime) Link(parentName, childName, alias string) error {
if child == nil {
return fmt.Errorf("Could not get container for %s", childName)
}
cc := runtime.Get(child.ID())
_, err := runtime.containerGraph.Set(path.Join(parentName, alias), cc.ID)
_, err := runtime.containerGraph.Set(path.Join(parentName, alias), child.ID())
return err
}