// UninstallPlugin uninstall the given plugin of the given version // If version is not specified, it uninstalls all the versions of given plugin func UninstallPlugin(pluginName string, version string) { pluginsHome, err := common.GetPrimaryPluginsInstallDir() if err != nil { logger.Fatalf("Failed to uninstall plugin %s. %s", pluginName, err.Error()) } if !common.DirExists(filepath.Join(pluginsHome, pluginName, version)) { logger.Errorf("Plugin %s not found.", strings.TrimSpace(pluginName+" "+version)) os.Exit(0) } var failed bool pluginsDir := filepath.Join(pluginsHome, pluginName) filepath.Walk(pluginsDir, func(dir string, info os.FileInfo, err error) error { if err == nil && info.IsDir() && dir != pluginsDir && strings.HasPrefix(filepath.Base(dir), version) { if err := uninstallVersionOfPlugin(dir, pluginName, filepath.Base(dir)); err != nil { logger.Errorf("Failed to uninstall plugin %s %s. %s", pluginName, version, err.Error()) failed = true } } return nil }) if failed { os.Exit(1) } if version == "" { if err := os.RemoveAll(pluginsDir); err != nil { logger.Fatalf("Failed to remove directory %s. %s", pluginsDir, err.Error()) } } }
func copyPluginFilesToGauge(installDesc *installDescription, versionInstallDesc *versionInstallDescription, pluginContents string) error { pluginsDir, err := common.GetPrimaryPluginsInstallDir() if err != nil { return err } versionedPluginDir := path.Join(pluginsDir, installDesc.Name, versionInstallDesc.Version) if common.DirExists(versionedPluginDir) { return errors.New(fmt.Sprintf("Plugin %s %s already installed at %s", installDesc.Name, versionInstallDesc.Version, versionedPluginDir)) } return common.MirrorDir(pluginContents, versionedPluginDir) }
func getPluginInstallDir(pluginID, pluginDirName string) (string, error) { pluginsDir, err := common.GetPrimaryPluginsInstallDir() if err != nil { return "", err } pluginDirPath := filepath.Join(pluginsDir, pluginID, pluginDirName) if common.DirExists(pluginDirPath) { return "", fmt.Errorf("Plugin %s %s already installed at %s", pluginID, pluginDirName, pluginDirPath) } return pluginDirPath, nil }
func copyPluginFilesToGaugeInstallDir(unzippedPluginDir string, pluginId string, version string) error { logger.Log.Info("Installing Plugin => %s %s\n", pluginId, version) pluginsDir, err := common.GetPrimaryPluginsInstallDir() if err != nil { return err } versionedPluginDir := path.Join(pluginsDir, pluginId, version) if common.DirExists(versionedPluginDir) { return errors.New(fmt.Sprintf("Plugin %s %s already installed at %s", pluginId, version, versionedPluginDir)) } return common.MirrorDir(unzippedPluginDir, versionedPluginDir) }
func UninstallPlugin(pluginName string) { pluginsDir, err := common.GetPrimaryPluginsInstallDir() if err != nil { handleUninstallFailure(err, pluginName) } pluginInstallationDir := path.Join(pluginsDir, pluginName) if common.DirExists(pluginInstallationDir) { if err = os.RemoveAll(pluginInstallationDir); err != nil { handleUninstallFailure(err, pluginName) } else { logger.Log.Info("%s plugin uninstalled successfully", pluginName) } } else { logger.Log.Info("%s plugin is not installed", pluginName) } }
func UninstallPlugin(pluginName string, version string) { pluginsDir, err := common.GetPrimaryPluginsInstallDir() if err != nil { handleUninstallFailure(err, pluginName) } pluginInfo := pluginName if version != "" { pluginInfo = fmt.Sprintf("%s(%s)", pluginName, version) } pluginInstallationDir := path.Join(pluginsDir, pluginName, version) if common.DirExists(pluginInstallationDir) { if err = os.RemoveAll(pluginInstallationDir); err != nil { handleUninstallFailure(err, pluginInfo) } else { logger.Info("%s plugin uninstalled successfully", pluginInfo) } } else { logger.Info("%s plugin is not installed", pluginInfo) } }