Skip to content

Commit e3204f6

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 6ec3266 commit e3204f6

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

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"
@@ -74,9 +75,14 @@ func addPluginCandidatesFromDir(res map[string][]string, d string) {
7475
return
7576
}
7677
for _, dentry := range dentries {
77-
switch dentry.Type() & os.ModeType { //nolint:exhaustive,nolintlint // no need to include all possible file-modes in this list
78-
case 0, os.ModeSymlink:
79-
// Regular file or symlink, keep going
78+
switch mode := dentry.Type() & os.ModeType; mode { //nolint:exhaustive,nolintlint // no need to include all possible file-modes in this list
79+
case os.ModeSymlink:
80+
if _, err := os.Stat(filepath.Join(d, dentry.Name())); errors.Is(err, os.ErrNotExist) {
81+
// Ignore broken symlink
82+
continue
83+
}
84+
case 0:
85+
// Regular file, keep going
8086
default:
8187
// Something else, ignore.
8288
continue

cli-plugins/manager/manager_test.go

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

0 commit comments

Comments
 (0)