The sqlite3 version in fedora (3.8) returns a different error string in the unique constraints
failure case than the one in hack/ (3.7). This updates the check to detect both, fixing
one integration check failure on Fedora.
Docker-DCO-1.1-Signed-off-by: Alexander Larsson <alexl@redhat.com> (github: alexlarsson)
| ... | ... |
@@ -4,6 +4,7 @@ import ( |
| 4 | 4 |
"database/sql" |
| 5 | 5 |
"fmt" |
| 6 | 6 |
"path" |
| 7 |
+ "strings" |
|
| 7 | 8 |
"sync" |
| 8 | 9 |
) |
| 9 | 10 |
|
| ... | ... |
@@ -51,6 +52,21 @@ type Database struct {
|
| 51 | 51 |
mux sync.RWMutex |
| 52 | 52 |
} |
| 53 | 53 |
|
| 54 |
+func IsNonUniqueNameError(err error) bool {
|
|
| 55 |
+ str := err.Error() |
|
| 56 |
+ // sqlite 3.7.17-1ubuntu1 returns: |
|
| 57 |
+ // Set failure: Abort due to constraint violation: columns parent_id, name are not unique |
|
| 58 |
+ if strings.HasSuffix(str, "name are not unique") {
|
|
| 59 |
+ return true |
|
| 60 |
+ } |
|
| 61 |
+ // sqlite-3.8.3-1.fc20 returns: |
|
| 62 |
+ // Set failure: Abort due to constraint violation: UNIQUE constraint failed: edge.parent_id, edge.name |
|
| 63 |
+ if strings.Contains(str, "UNIQUE constraint failed") && strings.Contains(str, "edge.name") {
|
|
| 64 |
+ return true |
|
| 65 |
+ } |
|
| 66 |
+ return false |
|
| 67 |
+} |
|
| 68 |
+ |
|
| 54 | 69 |
// Create a new graph database initialized with a root entity |
| 55 | 70 |
func NewDatabase(conn *sql.DB, init bool) (*Database, error) {
|
| 56 | 71 |
if conn == nil {
|
| ... | ... |
@@ -396,7 +396,7 @@ func (runtime *Runtime) Create(config *runconfig.Config, name string) (*Containe |
| 396 | 396 |
|
| 397 | 397 |
// Set the enitity in the graph using the default name specified |
| 398 | 398 |
if _, err := runtime.containerGraph.Set(name, id); err != nil {
|
| 399 |
- if !strings.HasSuffix(err.Error(), "name are not unique") {
|
|
| 399 |
+ if !graphdb.IsNonUniqueNameError(err) {
|
|
| 400 | 400 |
return nil, nil, err |
| 401 | 401 |
} |
| 402 | 402 |
|