Skip to content

Commit d231cf6

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 <github@gone.nl>
1 parent 3d3f780 commit d231cf6

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"
@@ -85,9 +86,14 @@ func addPluginCandidatesFromDir(res map[string][]string, d string) {
8586
return
8687
}
8788
for _, dentry := range dentries {
88-
switch dentry.Type() & os.ModeType {
89-
case 0, os.ModeSymlink:
90-
// Regular file or symlink, keep going
89+
switch mode := dentry.Type() & os.ModeType; mode {
90+
case os.ModeSymlink:
91+
if _, err := os.Stat(filepath.Join(d, dentry.Name())); errors.Is(err, os.ErrNotExist) {
92+
// Ignore broken symlink
93+
continue
94+
}
95+
case 0:
96+
// Regular file, keep going
9197
default:
9298
// Something else, ignore.
9399
continue

cli-plugins/manager/manager_test.go

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

0 commit comments

Comments
 (0)