Skip to content

Commit

Permalink
internal/mod/modpkgload: symbolic links can be valid CUE files too
Browse files Browse the repository at this point in the history
The test for whether there are any potential CUE files in a directory
was too naive when testing for file type: it should do what Go does [1]
and use the underlying information from symbolic links.

[1] https://github.com/golang/go/blob/fc51e5023ec99fee405ae61ee4ab2c8c9bc66f24/src/cmd/go/internal/imports/scan.go#L29

Fixes #3298

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: Id6cc3308e49c11c221e6af423c886050f6dbd5c6
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1198003
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
  • Loading branch information
rogpeppe committed Jul 19, 2024
1 parent a36cc32 commit f5b905c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
26 changes: 26 additions & 0 deletions cmd/cue/cmd/testdata/script/issue3298.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[!unix] skip
exec cp x/x.cue_actual x/x.cue
exec cue export
cmp stdout want-stdout

rm x/x.cue
exec ln -s x.cue_actual ./x/x.cue
exec cue export .

-- want-stdout --
{
"self": "x"
}
-- cue.mod/module.cue --
module: "example.com"

language: version: "v0.9.0"
-- main.cue --
package main

import "example.com/x"
x
-- x/x.cue_actual --
package x

self: "x"
15 changes: 14 additions & 1 deletion internal/mod/modpkgload/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,20 @@ func isDirWithCUEFiles(loc module.SourceLoc) (bool, error) {
return false, err
}
for _, e := range entries {
if strings.HasSuffix(e.Name(), ".cue") && e.Type().IsRegular() {
if !strings.HasSuffix(e.Name(), ".cue") {
continue
}
ftype := e.Type()
// If the directory entry is a symlink, stat it to obtain the info for the
// link target instead of the link itself.
if ftype&fs.ModeSymlink != 0 {
info, err := fs.Stat(loc.FS, filepath.Join(loc.Dir, e.Name()))
if err != nil {
continue // Ignore broken symlinks.
}
ftype = info.Mode()
}
if ftype.IsRegular() {
return true, nil
}
}
Expand Down

0 comments on commit f5b905c

Please sign in to comment.