Remove ioutil.

This commit is contained in:
Nuno Cruces 2022-05-13 12:19:46 +01:00
parent a9649cc64e
commit cf33a53ba0

View file

@ -3,7 +3,6 @@ package zenutil
import ( import (
"bytes" "bytes"
"context" "context"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -21,12 +20,12 @@ func Run(ctx context.Context, script string, data interface{}) ([]byte, error) {
if Command { if Command {
// Try to use syscall.Exec, fallback to exec.Command. // Try to use syscall.Exec, fallback to exec.Command.
if path, err := exec.LookPath("osascript"); err != nil { if path, err := exec.LookPath("osascript"); err != nil {
} else if t, err := ioutil.TempFile("", ""); err != nil { } else if t, err := os.CreateTemp("", ""); err != nil {
} else if err := os.Remove(t.Name()); err != nil { } else if err := os.Remove(t.Name()); err != nil {
} else if _, err := t.Write(buf.Bytes()); err != nil { } else if _, err := t.Write(buf.Bytes()); err != nil {
} else if _, err := t.Seek(0, 0); err != nil { } else if _, err := t.Seek(0, 0); err != nil {
} else if err := syscall.Dup2(int(t.Fd()), syscall.Stdin); err != nil {
} else if err := os.Stderr.Close(); err != nil { } else if err := os.Stderr.Close(); err != nil {
} else if err := syscall.Dup2(int(t.Fd()), syscall.Stdin); err != nil {
} else { } else {
syscall.Exec(path, []string{"osascript", "-l", "JavaScript"}, nil) syscall.Exec(path, []string{"osascript", "-l", "JavaScript"}, nil)
} }
@ -54,7 +53,7 @@ func RunProgress(ctx context.Context, max int, data Progress) (dlg *progressDial
return nil, err return nil, err
} }
t, err := ioutil.TempDir("", "") t, err := os.MkdirTemp("", "")
if err != nil { if err != nil {
return nil, err return nil, err
} }