Prevents removal of `podman.sock` file using `podman system reset` command

The `podman system reset` removes the `RunDirectory` directory as part of the machine reset, where `podman.sock` is usually stored.

Fixes: https://issues.redhat.com/browse/RHEL-71320

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
This commit is contained in:
Jan Rodák 2025-03-07 13:00:24 +01:00
parent d39806258a
commit 41924f870f
No known key found for this signature in database
GPG Key ID: D458A9B20435C2BF
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