diff --git a/gograph/gograph.go b/gograph/gograph.go index a8af0600cc..9f477c4cf5 100644 --- a/gograph/gograph.go +++ b/gograph/gograph.go @@ -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 diff --git a/runtime.go b/runtime.go index 3263d9cf7a..186ff4db8a 100644 --- a/runtime.go +++ b/runtime.go @@ -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 }