Skip to content

Commit f5b905c

Browse files
committed
internal/mod/modpkgload: symbolic links can be valid CUE files too
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 <[email protected]> Change-Id: Id6cc3308e49c11c221e6af423c886050f6dbd5c6 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1198003 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent a36cc32 commit f5b905c

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[!unix] skip
2+
exec cp x/x.cue_actual x/x.cue
3+
exec cue export
4+
cmp stdout want-stdout
5+
6+
rm x/x.cue
7+
exec ln -s x.cue_actual ./x/x.cue
8+
exec cue export .
9+
10+
-- want-stdout --
11+
{
12+
"self": "x"
13+
}
14+
-- cue.mod/module.cue --
15+
module: "example.com"
16+
17+
language: version: "v0.9.0"
18+
-- main.cue --
19+
package main
20+
21+
import "example.com/x"
22+
x
23+
-- x/x.cue_actual --
24+
package x
25+
26+
self: "x"

internal/mod/modpkgload/import.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,20 @@ func isDirWithCUEFiles(loc module.SourceLoc) (bool, error) {
249249
return false, err
250250
}
251251
for _, e := range entries {
252-
if strings.HasSuffix(e.Name(), ".cue") && e.Type().IsRegular() {
252+
if !strings.HasSuffix(e.Name(), ".cue") {
253+
continue
254+
}
255+
ftype := e.Type()
256+
// If the directory entry is a symlink, stat it to obtain the info for the
257+
// link target instead of the link itself.
258+
if ftype&fs.ModeSymlink != 0 {
259+
info, err := fs.Stat(loc.FS, filepath.Join(loc.Dir, e.Name()))
260+
if err != nil {
261+
continue // Ignore broken symlinks.
262+
}
263+
ftype = info.Mode()
264+
}
265+
if ftype.IsRegular() {
253266
return true, nil
254267
}
255268
}

0 commit comments

Comments
 (0)