mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
config/module: go back to the original folder when doing parent
references
This commit is contained in:
parent
bd4aaac71a
commit
2e11ca68df
@ -2,6 +2,7 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
@ -20,7 +21,26 @@ func (d *FileDetector) Detect(src, pwd string) (string, bool, error) {
|
|||||||
"relative paths require a module with a pwd")
|
"relative paths require a module with a pwd")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stat the pwd to determine if its a symbolic link. If it is,
|
||||||
|
// then the pwd becomes the original directory. Otherwise,
|
||||||
|
// `filepath.Join` below does some weird stuff.
|
||||||
|
//
|
||||||
|
// We just ignore if the pwd doesn't exist. That error will be
|
||||||
|
// caught later when we try to use the URL.
|
||||||
|
if fi, err := os.Lstat(pwd); !os.IsNotExist(err) {
|
||||||
|
if err != nil {
|
||||||
|
return "", true, err
|
||||||
|
}
|
||||||
|
if fi.Mode()&os.ModeSymlink != 0 {
|
||||||
|
pwd, err = os.Readlink(pwd)
|
||||||
|
if err != nil {
|
||||||
|
return "", true, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
src = filepath.Join(pwd, src)
|
src = filepath.Join(pwd, src)
|
||||||
|
println(src)
|
||||||
}
|
}
|
||||||
return fmtFileURL(src), true, nil
|
return fmtFileURL(src), true, nil
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ func TestTreeLoad_parentRef(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
actual := strings.TrimSpace(tree.String())
|
actual := strings.TrimSpace(tree.String())
|
||||||
expected := strings.TrimSpace(treeLoadStr)
|
expected := strings.TrimSpace(treeLoadParentStr)
|
||||||
if actual != expected {
|
if actual != expected {
|
||||||
t.Fatalf("bad: \n\n%s", actual)
|
t.Fatalf("bad: \n\n%s", actual)
|
||||||
}
|
}
|
||||||
@ -277,6 +277,11 @@ root
|
|||||||
foo
|
foo
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const treeLoadParentStr = `
|
||||||
|
root
|
||||||
|
a
|
||||||
|
b
|
||||||
|
`
|
||||||
const treeLoadSubdirStr = `
|
const treeLoadSubdirStr = `
|
||||||
root
|
root
|
||||||
foo
|
foo
|
||||||
|
Loading…
Reference in New Issue
Block a user