diff --git a/pkg/minikube/command/exec_runner.go b/pkg/minikube/command/exec_runner.go index 8b94d276e357..18840a8b70a4 100644 --- a/pkg/minikube/command/exec_runner.go +++ b/pkg/minikube/command/exec_runner.go @@ -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) + } } } @@ -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) + } }