mirror of
https://github.com/wader/fq.git
synced 2024-11-27 14:14:58 +03:00
interp: Make include abs path work again
This commit is contained in:
parent
1d83554b4a
commit
826c8bd555
@ -585,11 +585,17 @@ func (i *Interp) Eval(ctx context.Context, c interface{}, src string, srcFilenam
|
||||
{
|
||||
"", false, func(filename string) (io.Reader, error) {
|
||||
// TODO: jq $ORIGIN
|
||||
|
||||
if filepath.IsAbs(filename) {
|
||||
return i.os.FS().Open(filename)
|
||||
}
|
||||
|
||||
for _, path := range append([]string{"./"}, i.includePaths()...) {
|
||||
if f, err := i.os.FS().Open(filepath.Join(path, filename)); err == nil {
|
||||
return f, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, &fs.PathError{Op: "open", Path: filename, Err: fs.ErrNotExist}
|
||||
},
|
||||
},
|
||||
|
2
pkg/interp/testdata/incudepath.fqtest
vendored
2
pkg/interp/testdata/incudepath.fqtest
vendored
@ -6,6 +6,8 @@ $ fq --include-path /library -n 'include "a"; a'
|
||||
"a"
|
||||
$ fq -L /wrong -L /library -n 'include "a"; a'
|
||||
"a"
|
||||
$ fq -n 'include "/library/a"; a'
|
||||
"a"
|
||||
$ fq -L /wrong -n 'include "a"; a'
|
||||
exitcode: 3
|
||||
stderr:
|
||||
|
Loading…
Reference in New Issue
Block a user