mirror of
https://github.com/rclone/rclone.git
synced 2024-11-23 02:34:40 +08:00
5d6b8141ec
As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code.
43 lines
828 B
Go
43 lines
828 B
Go
//go:build (darwin || linux) && !gccgo
|
|
// +build darwin linux
|
|
// +build !gccgo
|
|
|
|
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
|
|
listing, err := os.ReadDir(dir)
|
|
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)
|
|
}
|
|
}
|
|
}
|