mirror of
https://github.com/containers/podman.git
synced 2025-06-07 15:48:37 +08:00

With the advent of Podman 2.0.0 we crossed the magical barrier of go modules. While we were able to continue importing all packages inside of the project, the project could not be vendored anymore from the outside. Move the go module to new major version and change all imports to `github.com/containers/libpod/v2`. The renaming of the imports was done via `gomove` [1]. [1] https://github.com/KSubedi/gomove Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
118 lines
2.5 KiB
Go
118 lines
2.5 KiB
Go
package libpod
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/containers/libpod/v2/libpod/define"
|
|
"github.com/containers/libpod/v2/pkg/rootless"
|
|
"github.com/containers/libpod/v2/pkg/util"
|
|
"github.com/pkg/errors"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// Reset removes all storage
|
|
func (r *Runtime) Reset(ctx context.Context) error {
|
|
|
|
pods, err := r.GetAllPods()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, p := range pods {
|
|
if err := r.RemovePod(ctx, p, true, true); err != nil {
|
|
if errors.Cause(err) == define.ErrNoSuchPod {
|
|
continue
|
|
}
|
|
logrus.Errorf("Error removing Pod %s: %v", p.ID(), err)
|
|
}
|
|
}
|
|
|
|
ctrs, err := r.GetAllContainers()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, c := range ctrs {
|
|
if err := r.RemoveContainer(ctx, c, true, true); err != nil {
|
|
if err := r.RemoveStorageContainer(c.ID(), true); err != nil {
|
|
if errors.Cause(err) == define.ErrNoSuchCtr {
|
|
continue
|
|
}
|
|
logrus.Errorf("Error removing container %s: %v", c.ID(), err)
|
|
}
|
|
}
|
|
}
|
|
|
|
if err := stopPauseProcess(); err != nil {
|
|
logrus.Errorf("Error stopping pause process: %v", err)
|
|
}
|
|
|
|
ir := r.ImageRuntime()
|
|
images, err := ir.GetImages()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, i := range images {
|
|
if err := i.Remove(ctx, true); err != nil {
|
|
if errors.Cause(err) == define.ErrNoSuchImage {
|
|
continue
|
|
}
|
|
logrus.Errorf("Error removing image %s: %v", i.ID(), err)
|
|
}
|
|
}
|
|
volumes, err := r.state.AllVolumes()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, v := range volumes {
|
|
if err := r.RemoveVolume(ctx, v, true); err != nil {
|
|
if errors.Cause(err) == define.ErrNoSuchVolume {
|
|
continue
|
|
}
|
|
logrus.Errorf("Error removing volume %s: %v", v.config.Name, err)
|
|
}
|
|
}
|
|
|
|
_, prevError := r.store.Shutdown(true)
|
|
if err := os.RemoveAll(r.store.GraphRoot()); err != nil {
|
|
if prevError != nil {
|
|
logrus.Error(prevError)
|
|
}
|
|
prevError = err
|
|
}
|
|
if err := os.RemoveAll(r.store.RunRoot()); err != nil {
|
|
if prevError != nil {
|
|
logrus.Error(prevError)
|
|
}
|
|
prevError = err
|
|
}
|
|
runtimeDir, err := util.GetRuntimeDir()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
tempDir := r.config.Engine.TmpDir
|
|
if tempDir == runtimeDir {
|
|
tempDir = filepath.Join(tempDir, "containers")
|
|
}
|
|
if err := os.RemoveAll(tempDir); err != nil {
|
|
if prevError != nil {
|
|
logrus.Error(prevError)
|
|
}
|
|
prevError = err
|
|
}
|
|
|
|
if rootless.IsRootless() {
|
|
configPath := filepath.Join(os.Getenv("HOME"), ".config/containers")
|
|
if err := os.RemoveAll(configPath); err != nil {
|
|
if prevError != nil {
|
|
logrus.Error(prevError)
|
|
}
|
|
prevError = err
|
|
}
|
|
}
|
|
|
|
return prevError
|
|
}
|