diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-12-17 12:05:33 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-17 12:05:33 +0000 |
commit | c38ae47a1adf3235d8b01d724e7327e608dd8078 (patch) | |
tree | 9fbdc40306c81b8ba260391f5d2b1b0444024466 | |
parent | 915ae6d9bfa39515d7280f29b5d7d072753cc788 (diff) | |
parent | 82424aa0079d69d96ce3a5f6d858465b6760709e (diff) | |
download | podman-c38ae47a1adf3235d8b01d724e7327e608dd8078.tar.gz podman-c38ae47a1adf3235d8b01d724e7327e608dd8078.tar.bz2 podman-c38ae47a1adf3235d8b01d724e7327e608dd8078.zip |
Merge pull request #8750 from rhatdan/reset
Don't accidently remove XDG_RUNTIME_DIR when reseting storage
-rw-r--r-- | libpod/reset.go | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/libpod/reset.go b/libpod/reset.go index 6d2842723..24efeed40 100644 --- a/libpod/reset.go +++ b/libpod/reset.go @@ -77,18 +77,35 @@ func (r *Runtime) Reset(ctx context.Context) error { } } + xdgRuntimeDir := filepath.Clean(os.Getenv("XDG_RUNTIME_DIR")) _, prevError := r.store.Shutdown(true) - if err := os.RemoveAll(r.store.GraphRoot()); err != nil { + graphRoot := filepath.Clean(r.store.GraphRoot()) + if graphRoot == xdgRuntimeDir { if prevError != nil { logrus.Error(prevError) } - prevError = err + prevError = errors.Errorf("failed to remove runtime graph root dir %s, since it is the same as XDG_RUNTIME_DIR", graphRoot) + } else { + if err := os.RemoveAll(graphRoot); err != nil { + if prevError != nil { + logrus.Error(prevError) + } + prevError = err + } } - if err := os.RemoveAll(r.store.RunRoot()); err != nil { + runRoot := filepath.Clean(r.store.RunRoot()) + if runRoot == xdgRuntimeDir { if prevError != nil { logrus.Error(prevError) } - prevError = err + prevError = errors.Errorf("failed to remove runtime root dir %s, since it is the same as XDG_RUNTIME_DIR", runRoot) + } else { + if err := os.RemoveAll(runRoot); err != nil { + if prevError != nil { + logrus.Error(prevError) + } + prevError = err + } } runtimeDir, err := util.GetRuntimeDir() if err != nil { @@ -98,13 +115,19 @@ func (r *Runtime) Reset(ctx context.Context) error { if tempDir == runtimeDir { tempDir = filepath.Join(tempDir, "containers") } - if err := os.RemoveAll(tempDir); err != nil { + if filepath.Clean(tempDir) == xdgRuntimeDir { if prevError != nil { logrus.Error(prevError) } - prevError = err + prevError = errors.Errorf("failed to remove runtime tmpdir %s, since it is the same as XDG_RUNTIME_DIR", tempDir) + } else { + if err := os.RemoveAll(tempDir); err != nil { + if prevError != nil { + logrus.Error(prevError) + } + prevError = err + } } - if storageConfPath, err := storage.DefaultConfigFile(rootless.IsRootless()); err == nil { if _, err = os.Stat(storageConfPath); err == nil { fmt.Printf("A storage.conf file exists at %s\n", storageConfPath) |