Avoid creation of irrelevant temporary files on Windows

Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
v0.8
Simon Ferquel 2020-04-27 15:44:57 +02:00
parent 1c4b5d11b3
commit 6d3f568629
3 changed files with 42 additions and 42 deletions

View File

@ -1,42 +0,0 @@
package binfmt_misc
import (
"bytes"
"compress/gzip"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
)
func check(bin string) error {
tmpdir, err := ioutil.TempDir("", "qemu-check")
if err != nil {
return err
}
defer os.RemoveAll(tmpdir)
pp := filepath.Join(tmpdir, "check")
r, err := gzip.NewReader(bytes.NewReader([]byte(bin)))
if err != nil {
return err
}
defer r.Close()
f, err := os.OpenFile(pp, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0700)
if err != nil {
return err
}
if _, err := io.Copy(f, r); err != nil {
f.Close()
return err
}
f.Close()
cmd := exec.Command("/check")
withChroot(cmd, tmpdir)
err = cmd.Run()
return err
}

View File

@ -3,7 +3,13 @@
package binfmt_misc
import (
"bytes"
"compress/gzip"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"syscall"
)
@ -12,3 +18,34 @@ func withChroot(cmd *exec.Cmd, dir string) {
Chroot: dir,
}
}
func check(bin string) error {
tmpdir, err := ioutil.TempDir("", "qemu-check")
if err != nil {
return err
}
defer os.RemoveAll(tmpdir)
pp := filepath.Join(tmpdir, "check")
r, err := gzip.NewReader(bytes.NewReader([]byte(bin)))
if err != nil {
return err
}
defer r.Close()
f, err := os.OpenFile(pp, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0700)
if err != nil {
return err
}
if _, err := io.Copy(f, r); err != nil {
f.Close()
return err
}
f.Close()
cmd := exec.Command("/check")
withChroot(cmd, tmpdir)
err = cmd.Run()
return err
}

View File

@ -3,8 +3,13 @@
package binfmt_misc
import (
"errors"
"os/exec"
)
func withChroot(cmd *exec.Cmd, dir string) {
}
func check(bin string) error {
return errors.New("binfmt is not supported on Windows")
}