Fix argless plugin install
A previous change altered the calculation of plugin sizes broke the
ability to install plugins that weren't backed by a directory.  This
fixes that by making getPluginSize act correctly for any kind of path.
@@ -395,26 +395,27 @@ func tryPlugin(file os.FileInfo) (PluginKind, string, semver.Version, bool) {
}
// getPluginSize recursively computes how much space is devoted to a given plugin.
-func getPluginSize(dir string) (int64, error) {
- files, err := ioutil.ReadDir(dir)
+func getPluginSize(path string) (int64, error) {
+ file, err := os.Stat(path)
if err != nil {
- if os.IsNotExist(err) {
return 0, nil
}
- return 0, err
- }
size := int64(0)
- for _, file := range files {
if file.IsDir() {
- sub, err := getPluginSize(filepath.Join(dir, file.Name()))
+ subs, err := ioutil.ReadDir(path)
if err != nil {
- return size, err
+ return 0, err
+ }
+ for _, child := range subs {
+ add, err := getPluginSize(filepath.Join(path, child.Name()))
+ if err != nil {
+ return 0, err
+ }
+ size += add
}
- size += sub
} else {
size += file.Size()
}
- }
return size, nil
}
