Don't remove config files with podman system reset

Check if storage.conf exists and display a message that
this file should be removed if it has not been modified.

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
This commit is contained in:
Paul Holzinger 2020-08-27 18:05:22 +02:00
parent cf6d9fe4e6
commit b84ddc2535
1 changed files with 11 additions and 7 deletions

View File

@ -2,12 +2,14 @@ package libpod
import ( import (
"context" "context"
"fmt"
"os" "os"
"path/filepath" "path/filepath"
"github.com/containers/podman/v2/libpod/define" "github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/pkg/rootless" "github.com/containers/podman/v2/pkg/rootless"
"github.com/containers/podman/v2/pkg/util" "github.com/containers/podman/v2/pkg/util"
"github.com/containers/storage"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -103,14 +105,16 @@ func (r *Runtime) Reset(ctx context.Context) error {
prevError = err prevError = err
} }
if rootless.IsRootless() { if storageConfPath, err := storage.DefaultConfigFile(rootless.IsRootless()); err == nil {
configPath := filepath.Join(os.Getenv("HOME"), ".config/containers") if _, err = os.Stat(storageConfPath); err == nil {
if err := os.RemoveAll(configPath); err != nil { fmt.Printf("A storage.conf file exists at %s\n", storageConfPath)
if prevError != nil { fmt.Println("You should remove this file if you did not modified the configuration.")
logrus.Error(prevError)
}
prevError = err
} }
} else {
if prevError != nil {
logrus.Error(prevError)
}
prevError = err
} }
return prevError return prevError