Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid creation of irrelevant temporary files on Windows #1462

Merged
merged 1 commit into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions util/binfmt_misc/check.go

This file was deleted.

37 changes: 37 additions & 0 deletions util/binfmt_misc/check_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
package binfmt_misc

import (
"bytes"
"compress/gzip"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"syscall"
)

Expand All @@ -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
}
5 changes: 5 additions & 0 deletions util/binfmt_misc/check_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}