Skip to content

Commit

Permalink
Merge pull request #1462 from simonferquel/dont-create-files-on-windows
Browse files Browse the repository at this point in the history
Avoid creation of irrelevant temporary files on Windows
  • Loading branch information
tonistiigi authored Apr 27, 2020
2 parents 1c4b5d1 + 6d3f568 commit e0b4ba5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
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")
}

0 comments on commit e0b4ba5

Please sign in to comment.