lang: funcs: Differentiate between empty and nil values

It would be good to differentiate between receiving an empty value or
not having received a value yet. This is similar to the previous commit.
This commit is contained in:
James Shubin
2020-01-03 00:28:54 -05:00
parent 762c53fb8d
commit 5cc960527e
4 changed files with 27 additions and 24 deletions

View File

@@ -40,7 +40,7 @@ type ReadFileAbsFunc struct {
data *interfaces.FuncData
last types.Value // last value received to use for diff
filename string // the active filename
filename *string // the active filename
result *string // last calculated output
closeChan chan struct{}
@@ -107,20 +107,21 @@ func (obj *ReadFileAbsFunc) Stream() error {
filename := input.Struct()["filename"].Str()
// TODO: add validation for absolute path?
if filename == obj.filename {
// TODO: add check for empty string
if obj.filename != nil && *obj.filename == filename {
continue // nothing changed
}
obj.filename = filename
obj.filename = &filename
fs, err := obj.init.World.Fs(obj.data.FsURI) // open the remote file system
if err != nil {
return errwrap.Wrapf(err, "can't load code from file system `%s`", obj.data.FsURI)
}
content, err := fs.ReadFile(obj.filename) // open the remote file system
content, err := fs.ReadFile(*obj.filename) // open the remote file system
// We could use it directly, but it feels like less correct.
//content, err := obj.data.Fs.ReadFile(obj.filename) // open the remote file system
//content, err := obj.data.Fs.ReadFile(*obj.filename) // open the remote file system
if err != nil {
return errwrap.Wrapf(err, "can't read file `%s`", obj.filename)
return errwrap.Wrapf(err, "can't read file `%s`", *obj.filename)
}
result := string(content) // convert to string