Skip to content

Commit 68164c4

Browse files
committed
cli-plugins/manager: ignore broken symlinks
Before this patch, a broken symlink would print a warning; docker info > /dev/null WARNING: Plugin "/Users/thajeztah/.docker/cli-plugins/docker-feedback" is not valid: failed to fetch metadata: fork/exec /Users/thajeztah/.docker/cli-plugins/docker-feedback: no such file or directory After this patch, such symlinks are ignored: docker info > /dev/null We should consider what the best approach is for these, as this patch will make them completely invisible, but we may still be iterating over them for discovery. We should als consider passing a "seen" map to de-duplicate entries. Entries can be either a direct symlink or in a symlinked path (for which we can filepath.EvalSymlinks). We need to benchmark the overhead of resolving the symlink vs possibly calling the plugin (to get their metadata) further down the line. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent ff5fdfa commit 68164c4

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

cli-plugins/manager/manager.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package manager
22

33
import (
44
"context"
5+
"errors"
56
"os"
67
"os/exec"
78
"path/filepath"
@@ -81,9 +82,14 @@ func addPluginCandidatesFromDir(res map[string][]string, d string) {
8182
return
8283
}
8384
for _, dentry := range dentries {
84-
switch dentry.Type() & os.ModeType {
85-
case 0, os.ModeSymlink:
86-
// Regular file or symlink, keep going
85+
switch mode := dentry.Type() & os.ModeType; mode {
86+
case os.ModeSymlink:
87+
if _, err := os.Stat(filepath.Join(d, dentry.Name())); errors.Is(err, os.ErrNotExist) {
88+
// Ignore broken symlink
89+
continue
90+
}
91+
case 0:
92+
// Regular file, keep going
8793
default:
8894
// Something else, ignore.
8995
continue

cli-plugins/manager/manager_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestListPluginCandidates(t *testing.T) {
3737
"plugins3-target", // Will be referenced as a symlink from below
3838
fs.WithFile("docker-plugin1", ""),
3939
fs.WithDir("ignored3"),
40-
fs.WithSymlink("docker-brokensymlink", "broken"), // A broken symlink is still a candidate (but would fail tests later)
40+
fs.WithSymlink("docker-brokensymlink", "broken"), // A broken symlink is ignored
4141
fs.WithFile("non-plugin-symlinked", ""), // This shouldn't appear, but ...
4242
fs.WithSymlink("docker-symlinked", "non-plugin-symlinked"), // ... this link to it should.
4343
),
@@ -71,9 +71,6 @@ func TestListPluginCandidates(t *testing.T) {
7171
"hardlink2": {
7272
dir.Join("plugins2", "docker-hardlink2"),
7373
},
74-
"brokensymlink": {
75-
dir.Join("plugins3", "docker-brokensymlink"),
76-
},
7774
"symlinked": {
7875
dir.Join("plugins3", "docker-symlinked"),
7976
},

0 commit comments

Comments
 (0)