github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/plugin/pluginenv/search_path.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package pluginenv
     5  
     6  import (
     7  	"io/ioutil"
     8  	"path/filepath"
     9  
    10  	"github.com/mattermost/mattermost-server/model"
    11  )
    12  
    13  // Performs a full scan of the given path.
    14  //
    15  // This function will return info for all subdirectories that appear to be plugins (i.e. all
    16  // subdirectories containing plugin manifest files, regardless of whether they could actually be
    17  // parsed).
    18  //
    19  // Plugins are found non-recursively and paths beginning with a dot are always ignored.
    20  func ScanSearchPath(path string) ([]*model.BundleInfo, error) {
    21  	files, err := ioutil.ReadDir(path)
    22  	if err != nil {
    23  		return nil, err
    24  	}
    25  	var ret []*model.BundleInfo
    26  	for _, file := range files {
    27  		if !file.IsDir() || file.Name()[0] == '.' {
    28  			continue
    29  		}
    30  		if info := model.BundleInfoForPath(filepath.Join(path, file.Name())); info.ManifestPath != "" {
    31  			ret = append(ret, info)
    32  		}
    33  	}
    34  	return ret, nil
    35  }