Plugins: Simplify plugin file removal (#66115)

* make explicit class check when attempting to remove plugin

* simplify plugin file tracking

* fix test

* apply feedback

* fix linter
This commit is contained in:
Will Browne
2023-04-20 10:52:59 +01:00
committed by GitHub
parent 6e8b17efd8
commit 739c7f1c68
15 changed files with 193 additions and 281 deletions

View File

@ -82,6 +82,17 @@ func (f LocalFS) Files() []string {
return files
}
func (f LocalFS) Remove() error {
// extra security check to ensure we only remove a directory that looks like a plugin
if _, err := os.Stat(filepath.Join(f.basePath, "plugin.json")); os.IsNotExist(err) {
if _, err = os.Stat(filepath.Join(f.basePath, "dist/plugin.json")); os.IsNotExist(err) {
return ErrUninstallInvalidPluginDir
}
}
return os.RemoveAll(f.basePath)
}
var _ fs.File = (*LocalFile)(nil)
// LocalFile implements a fs.File for accessing the local filesystem.