Skip to content

Commit

Permalink
cue: ignore bad symlinks and unusable file types
Browse files Browse the repository at this point in the history
- Ignore symlinks whose targets cannot be stat'd
- Ignore sockets, devices, etc.

closes cue-lang#1672

Signed-off-by: Kevin Burge <kcburge@pm.me>
  • Loading branch information
kcburge authored and Kevin Burge committed Apr 28, 2022
1 parent c942d0a commit 59ed280
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion cue/load/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,36 @@ func (l *loader) importPkg(pos token.Pos, p *build.Instance) []*build.Instance {
return retErr(errors.Wrapf(err, pos, "import failed reading dir %v", dirs[0][1]))
}
for _, f := range files {
if f.IsDir() {
switch mode := f.Mode(); mode & os.ModeType {
case 0:
case os.ModeDir:
continue
case os.ModeSymlink:
l, err := os.Stat(f.Name())
if err != nil {
p.UnknownFiles = append(p.UnknownFiles, &build.File{
Filename: f.Name(),
ExcludeReason: errors.Newf(token.NoPos, "bad link"),
})
continue // skip bad symlinks
}

switch lmode := l.Mode(); lmode & os.ModeType {
case 0:
case os.ModeDir:
continue
default:
p.UnknownFiles = append(p.UnknownFiles, &build.File{
Filename: f.Name(),
ExcludeReason: errors.Newf(token.NoPos, "unknown file %d", lmode),
})
}

default:
p.UnknownFiles = append(p.UnknownFiles, &build.File{
Filename: f.Name(),
ExcludeReason: errors.Newf(token.NoPos, "unknown file %d", mode),
})
continue
}
if f.Name() == "-" {
Expand Down

0 comments on commit 59ed280

Please sign in to comment.