File: plugin.go

package info (click to toggle)
rclone 1.60.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 34,832 kB
  • sloc: sh: 957; xml: 857; python: 655; javascript: 612; makefile: 269; ansic: 101; php: 74
file content (43 lines) | stat: -rw-r--r-- 845 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//go:build (darwin || linux) && !gccgo
// +build darwin linux
// +build !gccgo

package plugin

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"plugin"
	"strings"
)

func init() {
	dir := os.Getenv("RCLONE_PLUGIN_PATH")
	if dir == "" {
		return
	}
	// Get file names of plugin dir
	listing, err := ioutil.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)
		}
	}
}