mirror of https://github.com/containers/podman.git
Fix various lint issues
Signed-off-by: Matt Heon <mheon@redhat.com>
This commit is contained in:
parent
b4c4f9c93d
commit
8ab18d8482
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/containers/storage"
|
"github.com/containers/storage"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
// SQLite backend for database/sql
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ func NewSqliteState(runtime *Runtime) (_ State, defErr error) {
|
||||||
if _, err := state.conn.Exec("PRAGMA journal_mode = WAL;"); err != nil {
|
if _, err := state.conn.Exec("PRAGMA journal_mode = WAL;"); err != nil {
|
||||||
return nil, fmt.Errorf("switching journal to WAL mode: %w", err)
|
return nil, fmt.Errorf("switching journal to WAL mode: %w", err)
|
||||||
}
|
}
|
||||||
if _, err := state.conn.Exec("PRAGMA syncronous = FULL;"); err != nil {
|
if _, err := state.conn.Exec("PRAGMA synchronous = FULL;"); err != nil {
|
||||||
return nil, fmt.Errorf("setting full fsync mode in db: %w", err)
|
return nil, fmt.Errorf("setting full fsync mode in db: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +93,9 @@ func (s *SQLiteState) Refresh() (defErr error) {
|
||||||
// Retrieve all containers, pods, and volumes.
|
// Retrieve all containers, pods, and volumes.
|
||||||
// Maps are indexed by ID (or volume name) so we know which goes where,
|
// Maps are indexed by ID (or volume name) so we know which goes where,
|
||||||
// and store the marshalled state JSON
|
// and store the marshalled state JSON
|
||||||
var ctrStates, podStates, volumeStates map[string]string
|
ctrStates := make(map[string]string)
|
||||||
|
podStates := make(map[string]string)
|
||||||
|
volumeStates := make(map[string]string)
|
||||||
|
|
||||||
ctrRows, err := s.conn.Query("SELECT Id, Json FROM ContainerState;")
|
ctrRows, err := s.conn.Query("SELECT Id, Json FROM ContainerState;")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -117,12 +120,12 @@ func (s *SQLiteState) Refresh() (defErr error) {
|
||||||
// Refresh the state
|
// Refresh the state
|
||||||
resetContainerState(ctrState)
|
resetContainerState(ctrState)
|
||||||
|
|
||||||
stateJson, err := json.Marshal(ctrState)
|
newJSON, err := json.Marshal(ctrState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("marshalling container state json: %w", err)
|
return fmt.Errorf("marshalling container state json: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctrStates[id] = string(stateJson)
|
ctrStates[id] = string(newJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
podRows, err := s.conn.Query("SELECT Id, Json FROM PodState;")
|
podRows, err := s.conn.Query("SELECT Id, Json FROM PodState;")
|
||||||
|
@ -148,12 +151,12 @@ func (s *SQLiteState) Refresh() (defErr error) {
|
||||||
// Refresh the state
|
// Refresh the state
|
||||||
resetPodState(podState)
|
resetPodState(podState)
|
||||||
|
|
||||||
stateJson, err := json.Marshal(podState)
|
newJSON, err := json.Marshal(podState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("marshalling pod state json: %w", err)
|
return fmt.Errorf("marshalling pod state json: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
podStates[id] = string(stateJson)
|
podStates[id] = string(newJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
volRows, err := s.conn.Query("SELECT Name, Json FROM VolumeState;")
|
volRows, err := s.conn.Query("SELECT Name, Json FROM VolumeState;")
|
||||||
|
@ -168,7 +171,7 @@ func (s *SQLiteState) Refresh() (defErr error) {
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := volRows.Scan(&name, &stateJSON); err != nil {
|
if err := volRows.Scan(&name, &stateJSON); err != nil {
|
||||||
return fmt.Errorf("scanning volume state row: %w")
|
return fmt.Errorf("scanning volume state row: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
volState := new(VolumeState)
|
volState := new(VolumeState)
|
||||||
|
@ -180,12 +183,12 @@ func (s *SQLiteState) Refresh() (defErr error) {
|
||||||
// Refresh the state
|
// Refresh the state
|
||||||
resetVolumeState(volState)
|
resetVolumeState(volState)
|
||||||
|
|
||||||
stateJson, err := json.Marshal(volState)
|
newJSON, err := json.Marshal(volState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("marshalling volume state json: %w", err)
|
return fmt.Errorf("marshalling volume state json: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
volumeStates[name] = string(stateJson)
|
volumeStates[name] = string(newJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write updated states back to DB, and perform additional maintenance
|
// Write updated states back to DB, and perform additional maintenance
|
||||||
|
@ -549,7 +552,7 @@ func (s *SQLiteState) HasContainer(id string) (bool, error) {
|
||||||
}
|
}
|
||||||
return false, fmt.Errorf("looking up container %s in database: %w", id, err)
|
return false, fmt.Errorf("looking up container %s in database: %w", id, err)
|
||||||
} else if check != 1 {
|
} else if check != 1 {
|
||||||
return false, fmt.Errorf("check digit for container %s lookup incorrect", id, define.ErrInternal)
|
return false, fmt.Errorf("check digit for container %s lookup incorrect: %w", id, define.ErrInternal)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/containers/podman/v4/libpod/define"
|
"github.com/containers/podman/v4/libpod/define"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
// SQLite backend for database/sql
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -364,11 +365,12 @@ func (s *SQLiteState) addContainer(ctr *Container) (defErr error) {
|
||||||
return fmt.Errorf("container dependency %s does not exist in database: %w", dep, define.ErrNoSuchCtr)
|
return fmt.Errorf("container dependency %s does not exist in database: %w", dep, define.ErrNoSuchCtr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ctr.config.Pod == "" && depPod.Valid {
|
switch {
|
||||||
|
case ctr.config.Pod == "" && depPod.Valid:
|
||||||
return fmt.Errorf("container dependency %s is part of a pod, but container is not: %w", dep, define.ErrInvalidArg)
|
return fmt.Errorf("container dependency %s is part of a pod, but container is not: %w", dep, define.ErrInvalidArg)
|
||||||
} else if ctr.config.Pod != "" && !depPod.Valid {
|
case ctr.config.Pod != "" && !depPod.Valid:
|
||||||
return fmt.Errorf("container dependency %s is not part of a pod, but this container belongs to pod %s", dep, ctr.config.Pod, define.ErrInvalidArg)
|
return fmt.Errorf("container dependency %s is not part of pod, but this container belongs to pod %s: %w", dep, ctr.config.Pod, define.ErrInvalidArg)
|
||||||
} else if ctr.config.Pod != "" && depPod.String != ctr.config.Pod {
|
case ctr.config.Pod != "" && depPod.String != ctr.config.Pod:
|
||||||
return fmt.Errorf("container dependency %s is part of pod %s but container is part of pod %s, pods must match: %w", dep, depPod.String, ctr.config.Pod, define.ErrInvalidArg)
|
return fmt.Errorf("container dependency %s is part of pod %s but container is part of pod %s, pods must match: %w", dep, depPod.String, ctr.config.Pod, define.ErrInvalidArg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue