Пример #1
0
func getLatestInstalledPlugin(pluginDir string) (*PluginInfo, error) {
	files, err := ioutil.ReadDir(pluginDir)
	if err != nil {
		return nil, fmt.Errorf("Error listing files in plugin directory %s: %s", pluginDir, err.Error())
	}
	versionToPlugins := make(map[*version.Version][]PluginInfo, 0)
	pluginName := filepath.Base(pluginDir)

	for _, file := range files {
		if file.IsDir() {
			var v *version.Version
			var err error
			if strings.Contains(file.Name(), "nightly") {
				v, err = version.ParseVersion(file.Name()[:strings.LastIndex(file.Name(), ".")])
			} else {
				v, err = version.ParseVersion(file.Name())
			}
			if err == nil {
				versionToPlugins[v] = append(versionToPlugins[v], PluginInfo{pluginName, v, filepath.Join(pluginDir, file.Name())})
			}
		}
	}

	if len(versionToPlugins) < 1 {
		return nil, fmt.Errorf("No valid versions of plugin %s found in %s", pluginName, pluginDir)
	}
	var availableVersions []*version.Version
	for k := range versionToPlugins {
		availableVersions = append(availableVersions, k)
	}
	latestVersion := version.GetLatestVersion(availableVersions)
	latestBuild := getLatestOf(versionToPlugins[latestVersion], latestVersion)
	return &latestBuild, nil
}
Пример #2
0
func getPluginLatestVersion(pluginDir string) (*version.Version, error) {
	files, err := ioutil.ReadDir(pluginDir)
	if err != nil {
		return nil, fmt.Errorf("Error listing files in plugin directory %s: %s", pluginDir, err.Error())
	}
	availableVersions := make([]*version.Version, 0)

	for _, file := range files {
		if file.IsDir() {
			version, err := version.ParseVersion(file.Name())
			if err == nil {
				availableVersions = append(availableVersions, version)
			}
		}
	}
	pluginName := filepath.Base(pluginDir)

	if len(availableVersions) < 1 {
		return nil, fmt.Errorf("No valid versions of plugin %s found in %s", pluginName, pluginDir)
	}
	latestVersion := version.GetLatestVersion(availableVersions)
	return latestVersion, nil
}
Пример #3
0
func GetAllInstalledPluginsWithVersion() ([]PluginInfo, error) {
	pluginInstallPrefixes, err := common.GetPluginInstallPrefixes()
	if err != nil {
		return nil, err
	}
	allPlugins := make(map[string]PluginInfo, 0)
	for _, prefix := range pluginInstallPrefixes {
		files, err := ioutil.ReadDir(prefix)
		if err != nil {
			return nil, err
		}
		for _, file := range files {
			pluginDir, err := os.Stat(filepath.Join(prefix, file.Name()))
			if err != nil {
				continue
			}
			if pluginDir.IsDir() {
				latestPlugin, err := getLatestInstalledPlugin(filepath.Join(prefix, file.Name()))
				if err != nil {
					continue
				}
				pluginAdded, repeated := allPlugins[file.Name()]
				if repeated {
					var availableVersions []*version.Version
					availableVersions = append(availableVersions, pluginAdded.Version, latestPlugin.Version)
					latest := version.GetLatestVersion(availableVersions)
					if latest.IsEqualTo(latestPlugin.Version) {
						allPlugins[file.Name()] = *latestPlugin
					}
				} else {
					allPlugins[file.Name()] = *latestPlugin
				}
			}
		}
	}
	return sortPlugins(allPlugins), nil
}