77 "os"
88 "os/exec"
99 "path/filepath"
10+ "io/fs"
11+ "errors"
1012
1113 "github.com/spf13/cobra"
1214)
@@ -25,7 +27,7 @@ func init() {
2527}
2628
2729func uninstall (cmd * cobra.Command , args []string ) error {
28- userName , _ , _ , err := getUser ()
30+ userName , _ , homeDir , err := getUser ()
2931 if err != nil {
3032 return err
3133 }
@@ -54,5 +56,35 @@ func uninstall(cmd *cobra.Command, args []string) error {
5456 if err := os .RemoveAll (helperPath ); err != nil {
5557 return fmt .Errorf ("could not remove helper binary path: %s" , helperPath )
5658 }
59+
60+ // Get the file information of dockerSock
61+ if _ , err := os .Lstat (dockerSock ); err != nil {
62+ // If the error is due to the file not existing, return nil
63+ if errors .Is (err , fs .ErrNotExist ) {
64+ return nil
65+ }
66+ // Return an error if unable to get the file information
67+ return fmt .Errorf ("could not stat dockerSock: %v" , err )
68+ }
69+ if target , err := os .Readlink (dockerSock ); err != nil {
70+ //Return an error if unable to read the symlink
71+ return fmt .Errorf ("could not read dockerSock symlink: %v" , err )
72+ } else {
73+ // Check if the target of the symlink matches the expected target
74+ expectedTarget := filepath .Join (homeDir , ".local" , "share" , "containers" , "podman" , "machine" , "podman.sock" )
75+ if target != expectedTarget {
76+ // If the targets do not match, print the information and return with nothing left to do
77+ fmt .Printf ("dockerSock does not point to the expected target: %v\n " , target )
78+ return nil
79+ }
80+
81+ // Attempt to remove dockerSock
82+ if err := os .Remove (dockerSock ); err != nil {
83+ if ! errors .Is (err , fs .ErrNotExist ) {
84+ return fmt .Errorf ("could not remove dockerSock file: %s" , err )
85+ }
86+ }
87+ }
88+
5789 return nil
5890}
0 commit comments