Переглянути джерело

Move name parsing logic to GetByName method

Michael Crosby 11 роки тому
батько
коміт
7c882a8003
2 змінених файлів з 6 додано та 8 видалено
  1. 1 2
      gograph/gograph.go
  2. 5 6
      runtime.go

+ 1 - 2
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

+ 5 - 6
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
 }