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.

Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

closes cue-lang#1672

Signed-off-by: Kevin Burge <kcburge@pm.me>
  • Loading branch information
kcburge committed Apr 27, 2022
1 parent c942d0a commit 8d4de61
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 8d4de61

Please sign in to comment.