mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
sqlite: return correct error on pod-name conflict
I wasn't able to find a way to get error-checks working with the sqlite3 library with the time at hand. [NO NEW TESTS NEEDED] Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
@ -1470,6 +1470,19 @@ func (s *SQLiteState) AddPod(pod *Pod) (defErr error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// TODO: explore whether there's a more idiomatic way to do error checks for the name.
|
||||||
|
// There is a sqlite3.ErrConstraintUnique error but I (vrothberg) couldn't find a way
|
||||||
|
// to work with the returned errors yet.
|
||||||
|
var check int
|
||||||
|
row := tx.QueryRow("SELECT 1 FROM PodConfig WHERE Name=?;", pod.Name())
|
||||||
|
if err := row.Scan(&check); err != nil {
|
||||||
|
if !errors.Is(err, sql.ErrNoRows) {
|
||||||
|
return fmt.Errorf("checking if pod name %s exists in database: %w", pod.ID(), err)
|
||||||
|
}
|
||||||
|
} else if check != 0 {
|
||||||
|
return fmt.Errorf("name \"%s\" is in use: %w", pod.Name(), define.ErrPodExists)
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := tx.Exec("INSERT INTO IDNamespace VALUES (?);", pod.ID()); err != nil {
|
if _, err := tx.Exec("INSERT INTO IDNamespace VALUES (?);", pod.ID()); err != nil {
|
||||||
return fmt.Errorf("adding pod id to database: %w", err)
|
return fmt.Errorf("adding pod id to database: %w", err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user