Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 2e11ca6

Browse files
committed
config/module: go back to the original folder when doing parent
references
1 parent bd4aaac commit 2e11ca6

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

config/module/detect_file.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package module
22

33
import (
44
"fmt"
5+
"os"
56
"path/filepath"
67
"runtime"
78
)
@@ -20,7 +21,26 @@ func (d *FileDetector) Detect(src, pwd string) (string, bool, error) {
2021
"relative paths require a module with a pwd")
2122
}
2223

24+
// Stat the pwd to determine if its a symbolic link. If it is,
25+
// then the pwd becomes the original directory. Otherwise,
26+
// `filepath.Join` below does some weird stuff.
27+
//
28+
// We just ignore if the pwd doesn't exist. That error will be
29+
// caught later when we try to use the URL.
30+
if fi, err := os.Lstat(pwd); !os.IsNotExist(err) {
31+
if err != nil {
32+
return "", true, err
33+
}
34+
if fi.Mode()&os.ModeSymlink != 0 {
35+
pwd, err = os.Readlink(pwd)
36+
if err != nil {
37+
return "", true, err
38+
}
39+
}
40+
}
41+
2342
src = filepath.Join(pwd, src)
43+
println(src)
2444
}
2545
return fmtFileURL(src), true, nil
2646
}

config/module/tree_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func TestTreeLoad_parentRef(t *testing.T) {
126126
}
127127

128128
actual := strings.TrimSpace(tree.String())
129-
expected := strings.TrimSpace(treeLoadStr)
129+
expected := strings.TrimSpace(treeLoadParentStr)
130130
if actual != expected {
131131
t.Fatalf("bad: \n\n%s", actual)
132132
}
@@ -277,6 +277,11 @@ root
277277
foo
278278
`
279279

280+
const treeLoadParentStr = `
281+
root
282+
a
283+
b
284+
`
280285
const treeLoadSubdirStr = `
281286
root
282287
foo

0 commit comments

Comments
 (0)