#Is it possible to Lstat a file/dir in a
1 messages · Page 1 of 1 (latest)
This is what I ended up with
const fileOrDir = `
F=%s
if [[ -d $F ]]; then
echo "directory"
elif [[ -f $F ]]; then
echo "file"
else
echo "$F is not valid"
exit 1
fi
`
...
co, err := c.Built.WithExec([]string{"sh", "-c", fmt.Sprintf(fileOrDir, src)}, dagger.ContainerWithExecOpts{
RedirectStdout: "/tmp/stdout",
}).Sync(rt.Ctx)
if err != nil {
return err
}
f := co.File("/tmp/stdout")
fc, err := f.Contents(rt.Ctx)
if err != nil {
return err
}
fc = strings.TrimSpace(fc)
// file vs dir
if fc == "file" {
f := c.Built.File(src)
comp.Final = comp.Final.WithFile(dst, f)
} else {
d := c.Built.Directory(src)
comp.Final = comp.Final.WithDirectory(dst, d)
}
}