Merge pull request #25504 from Honny1/sys-reset-podman-socket

Fix `podman system reset` deletes the `podman.sock`
This commit is contained in:
openshift-merge-bot[bot]
2025-03-11 17:39:17 +00:00
committed by GitHub
4 changed files with 26 additions and 1 deletions

View File

@ -20,6 +20,7 @@ var (
systemResetDescription = `Reset podman storage back to default state
All containers will be stopped and removed, and all images, volumes, networks and container content will be removed.
This command does not restart podman.service and podman.socket systemd units. You may need to manually restart it after running this command.
`
systemResetCommand = &cobra.Command{
Annotations: map[string]string{registry.EngineMode: registry.ABIMode},

View File

@ -67,7 +67,7 @@ func resetMachine() error {
logrus.Errorf("unable to remove machine data dir %q: %q", dirs.DataDir.GetPath(), err)
}
if err := utils.GuardedRemoveAll(dirs.RuntimeDir.GetPath()); err != nil {
if err := utils.RemoveFilesExcept(dirs.RuntimeDir.GetPath(), "podman.sock"); err != nil {
logrus.Errorf("unable to remove machine runtime dir %q: %q", dirs.RuntimeDir.GetPath(), err)
}

View File

@ -19,6 +19,8 @@ or `volume_path`.
of the relevant configurations. If the administrator modified the configuration files first,
`podman system reset` might not be able to clean up the previous storage.
`podman system reset` does not restart podman.service and podman.socket systemd units. You may need to manually restart it after running this command.
## OPTIONS
#### **--force**, **-f**

View File

@ -6,6 +6,7 @@ import (
"io"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
@ -119,6 +120,27 @@ func GuardedRemoveAll(path string) error {
return os.RemoveAll(path)
}
// RemoveFilesExcept removes all files in a directory except for the one specified
// by excludeFile and will not delete certain catastrophic paths.
func RemoveFilesExcept(path string, excludeFile string) error {
if path == "" || path == "/" {
return fmt.Errorf("refusing to recursively delete `%s`", path)
}
files, err := os.ReadDir(path)
if err != nil {
return err
}
for _, file := range files {
if file.Name() != excludeFile {
if err := os.RemoveAll(filepath.Join(path, file.Name())); err != nil {
return err
}
}
}
return nil
}
func ProgressBar(prefix string, size int64, onComplete string) (*mpb.Progress, *mpb.Bar) {
p := mpb.New(
mpb.WithWidth(80), // Do not go below 80, see bug #17718