diff --git a/pkg/graphdb/graphdb.go b/pkg/graphdb/graphdb.go index 9e2466b692..46a23b1e7b 100644 --- a/pkg/graphdb/graphdb.go +++ b/pkg/graphdb/graphdb.go @@ -4,6 +4,7 @@ import ( "database/sql" "fmt" "path" + "strings" "sync" ) @@ -51,6 +52,21 @@ type Database struct { mux sync.RWMutex } +func IsNonUniqueNameError(err error) bool { + str := err.Error() + // sqlite 3.7.17-1ubuntu1 returns: + // Set failure: Abort due to constraint violation: columns parent_id, name are not unique + if strings.HasSuffix(str, "name are not unique") { + return true + } + // sqlite-3.8.3-1.fc20 returns: + // Set failure: Abort due to constraint violation: UNIQUE constraint failed: edge.parent_id, edge.name + if strings.Contains(str, "UNIQUE constraint failed") && strings.Contains(str, "edge.name") { + return true + } + return false +} + // Create a new graph database initialized with a root entity func NewDatabase(conn *sql.DB, init bool) (*Database, error) { if conn == nil { diff --git a/runtime.go b/runtime.go index 0c2c17d7a4..6cebab6e1c 100644 --- a/runtime.go +++ b/runtime.go @@ -396,7 +396,7 @@ func (runtime *Runtime) Create(config *runconfig.Config, name string) (*Containe // Set the enitity in the graph using the default name specified if _, err := runtime.containerGraph.Set(name, id); err != nil { - if !strings.HasSuffix(err.Error(), "name are not unique") { + if !graphdb.IsNonUniqueNameError(err) { return nil, nil, err }