wasi-module-sdk-go/exec/lookup.go

43 lines
902 B
Go

package exec
import (
"errors"
"fmt"
rpcv1 "code.icb4dc0.de/buildr/api/generated/rpc/v1"
"code.icb4dc0.de/buildr/wasi-module-sdk-go/mem"
)
func LookPath(file string) (string, error) {
lookupPathReq := &rpcv1.LookupPathRequest{
Command: file,
}
data, err := lookupPathReq.MarshalVT()
if err != nil {
return "", err
}
result := _lookPath(mem.DataToManagedPtr(data))
if result == 0 {
return "", fmt.Errorf("failed to lookup in path: %s", file)
}
resultPtr := uint32(result >> 32)
resultSize := uint32(result)
if resultSize == 0 {
return "", fmt.Errorf("failed to lookup in path: %s", file)
}
lookupPathResp := new(rpcv1.LookupPathResponse)
if err := lookupPathResp.UnmarshalVT(mem.PtrToData(resultPtr, resultSize)); err != nil {
return "", err
}
if len(lookupPathResp.Error) > 0 {
return "", errors.New(lookupPathResp.Error)
}
return lookupPathResp.Path, nil
}