| package dkms | |
| import ( | |
| "cos.googlesource.com/cos/tools.git/src/pkg/utils" | |
| "fmt" | |
| "github.com/golang/glog" | |
| "os" | |
| ) | |
| // Uninstall removes all of the installed modules of a DKMS package from the | |
| // install tree. | |
| func Uninstall(pkg *Package) error { | |
| if !IsInstalled(pkg) { | |
| glog.Info("module is not installed; skipping removal from install tree") | |
| return nil | |
| } | |
| for _, module := range pkg.Config.Modules { | |
| destModulePath := module.DestPath() | |
| glog.Info("removing installed module", destModulePath) | |
| if err := os.Remove(destModulePath); err != nil { | |
| if os.IsNotExist(err) { | |
| glog.Warningf("could not find module at %s", destModulePath, pkg.Name) | |
| } else { | |
| return fmt.Errorf("error removing module %s", destModulePath) | |
| } | |
| } | |
| } | |
| // Unintuitively, Dell DKMS does POST_REMOVE after uninstall, not after remove. | |
| if pkg.Config.PostRemove != "" { | |
| if err := utils.RunCommandString(pkg.SourceDir(), pkg.Config.PostRemove, os.Stderr); err != nil { | |
| return fmt.Errorf("failed to run post-remove script: %v", err) | |
| } | |
| } | |
| return nil | |
| } |