mirror of
https://github.com/containers/podman.git
synced 2025-07-04 10:10:32 +08:00
sqlite: addContainer: add named volume only once
There's a unique constraint in the table, so we shouldn't add the same volume more than once to the same container. [NO NEW TESTS NEEDED] as it fixes an existing one. Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
@ -399,9 +399,13 @@ func (s *SQLiteState) addContainer(ctr *Container) (defErr error) {
|
||||
return fmt.Errorf("adding container dependency %s to database: %w", dep, err)
|
||||
}
|
||||
}
|
||||
volMap := make(map[string]bool)
|
||||
for _, vol := range ctr.config.NamedVolumes {
|
||||
if _, err := tx.Exec("INSERT INTO ContainerVolume VALUES (?, ?);", ctr.ID(), vol.Name); err != nil {
|
||||
return fmt.Errorf("adding container volume %s to database: %w", vol.Name, err)
|
||||
if _, ok := volMap[vol.Name]; !ok {
|
||||
if _, err := tx.Exec("INSERT INTO ContainerVolume VALUES (?, ?);", ctr.ID(), vol.Name); err != nil {
|
||||
return fmt.Errorf("adding container volume %s to database: %w", vol.Name, err)
|
||||
}
|
||||
volMap[vol.Name] = true
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user