mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-27 19:36:19 +00:00
@@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -153,6 +154,7 @@ func (r *registry) readPluginsDir(dir string) ([]string, error) {
|
||||
}
|
||||
|
||||
if !executable(file) {
|
||||
r.logger.Warnf("Searching plugin skip file %s, not executable, mode %v, ext %s", file.Name(), file.Mode(), strings.ToLower(filepath.Ext(file.Name())))
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -163,6 +165,15 @@ func (r *registry) readPluginsDir(dir string) ([]string, error) {
|
||||
|
||||
// executable determines if a file is executable.
|
||||
func executable(info os.FileInfo) bool {
|
||||
return executableLinux(info) || executableWindows(info)
|
||||
}
|
||||
|
||||
func executableWindows(info os.FileInfo) bool {
|
||||
ext := strings.ToLower(filepath.Ext(info.Name()))
|
||||
return (ext == ".exe")
|
||||
}
|
||||
|
||||
func executableLinux(info os.FileInfo) bool {
|
||||
/*
|
||||
When we AND the mode with 0111:
|
||||
|
||||
|
||||
@@ -114,7 +114,9 @@ func TestReadPluginsDir(t *testing.T) {
|
||||
WithFileAndMode("/plugins/nonexecutable2", []byte("plugin2"), 0644).
|
||||
WithFileAndMode("/plugins/executable3", []byte("plugin3"), 0755).
|
||||
WithFileAndMode("/plugins/nested/executable4", []byte("plugin4"), 0755).
|
||||
WithFileAndMode("/plugins/nested/nonexecutable5", []byte("plugin4"), 0644)
|
||||
WithFileAndMode("/plugins/nested/nonexecutable5", []byte("plugin4"), 0644).
|
||||
WithFileAndMode("/plugins/nested/win-exe1.exe", []byte("plugin4"), 0600).
|
||||
WithFileAndMode("/plugins/nested/WIN-EXE2.EXE", []byte("plugin4"), 0600)
|
||||
|
||||
plugins, err := r.readPluginsDir(dir)
|
||||
require.NoError(t, err)
|
||||
@@ -123,6 +125,8 @@ func TestReadPluginsDir(t *testing.T) {
|
||||
"/plugins/executable1",
|
||||
"/plugins/executable3",
|
||||
"/plugins/nested/executable4",
|
||||
"/plugins/nested/win-exe1.exe",
|
||||
"/plugins/nested/WIN-EXE2.EXE",
|
||||
}
|
||||
|
||||
sort.Strings(plugins)
|
||||
|
||||
Reference in New Issue
Block a user