Skip to content

Commit

Permalink
make tests pass again for non-Linux systems
Browse files Browse the repository at this point in the history
  • Loading branch information
Git-Jiro committed Oct 4, 2020
1 parent 5fd7f48 commit fc8ea8d
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions pkg/minikube/command/exec_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@ func (e *execRunner) Copy(f assets.CopyableFile) error {
dst := path.Join(f.GetTargetDir(), f.GetTargetName())
if _, err := os.Stat(dst); err == nil {
glog.Infof("found %s, removing ...", dst)
if _, err := e.RunCmd(exec.Command("sudo", "rm", "-f", dst)); err != nil {
return errors.Wrapf(err, "error removing file %s", dst)
switch runtime.goos {
case "linux":
if _, err := e.RunCmd(exec.Command("sudo", "rm", "-f", dst)); err != nil {
return errors.Wrapf(err, "error removing file %s", dst)
}
default:
if err := os.Remove(dst); err != nil {
return errors.Wrapf(err, "error removing file %s", dst)
}
}
}

Expand All @@ -106,27 +113,38 @@ func (e *execRunner) Copy(f assets.CopyableFile) error {
return errors.Wrapf(err, "error converting permissions %s to integer", f.GetPermissions())
}

// write to TMP location ...
tmpfile, err := ioutil.TempFile("", "minikube")
if err != nil {
return errors.Wrapf(err, "error creating tempfile")
}
defer os.Remove(tmpfile.Name())
err = writeFile(tmpfile.Name(), f, os.FileMode(perms))
if err != nil {
return errors.Wrapf(err, "error writing to tempfile %s", tmpfile.Name())
switch runtime.goos {
case "linux":
// write to TMP location ...
tmpfile, err := ioutil.TempFile("", "minikube")
if err != nil {
return errors.Wrapf(err, "error creating tempfile")
}
defer os.Remove(tmpfile.Name())
err = writeFile(tmpfile.Name(), f, os.FileMode(perms))
if err != nil {
return errors.Wrapf(err, "error writing to tempfile %s", tmpfile.Name())
}
// ... then use SUDO to move to target
// then sudo cp -a src dst
_, err = e.RunCmd(exec.Command("sudo", "cp", "-a", tmpfile.Name(), dst))
return err

default:
return writeFile(dst, f, os.FileMode(perms))
}
// ... then use SUDO to move to target
// then sudo cp -a src dst
_, err = e.RunCmd(exec.Command("sudo", "cp", "-a", tmpfile.Name(), dst))

return err
}

// Remove removes a file
func (e *execRunner) Remove(f assets.CopyableFile) error {
dst := filepath.Join(f.GetTargetDir(), f.GetTargetName())
glog.Infof("rm: %s", dst)
_, err := e.RunCmd(exec.Command("sudo", "rm", "-f", dst))
return err
switch runtime.goos {
case "linux":
_, err := e.RunCmd(exec.Command("sudo", "rm", "-f", dst))
return err
default:
return os.Remove(dst)
}
}

0 comments on commit fc8ea8d

Please sign in to comment.