2021-09-09 12:25:25 +00:00
|
|
|
//go:build (darwin || linux) && !gccgo
|
2019-09-23 00:41:02 +00:00
|
|
|
// +build darwin linux
|
2020-07-28 08:56:10 +00:00
|
|
|
// +build !gccgo
|
2019-09-23 00:41:02 +00:00
|
|
|
|
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"plugin"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
dir := os.Getenv("RCLONE_PLUGIN_PATH")
|
|
|
|
if dir == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// Get file names of plugin dir
|
2022-08-20 14:38:02 +00:00
|
|
|
listing, err := os.ReadDir(dir)
|
2019-09-23 00:41:02 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, "Failed to open plugin directory:", err)
|
|
|
|
}
|
|
|
|
// Enumerate file names, load valid plugins
|
|
|
|
for _, file := range listing {
|
|
|
|
// Match name
|
|
|
|
fileName := file.Name()
|
|
|
|
if !strings.HasPrefix(fileName, "librcloneplugin_") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !strings.HasSuffix(fileName, ".so") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// Try to load plugin
|
|
|
|
_, err := plugin.Open(filepath.Join(dir, fileName))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "Failed to load plugin %s: %s\n",
|
|
|
|
fileName, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|