<commit_before>/*
Copyright 2016 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
	"fmt"
	"net"
	"os"
	"os/signal"
	"runtime"
	"strconv"
	"strings"
	"sync"
	"syscall"

	"github.com/pkg/errors"
	"github.com/spf13/cobra"
	"k8s.io/klog/v2"
	"k8s.io/minikube/pkg/minikube/cluster"
	"k8s.io/minikube/pkg/minikube/detect"
	"k8s.io/minikube/pkg/minikube/driver"
	"k8s.io/minikube/pkg/minikube/exit"
	"k8s.io/minikube/pkg/minikube/mustload"
	"k8s.io/minikube/pkg/minikube/out"
	"k8s.io/minikube/pkg/minikube/reason"
	"k8s.io/minikube/pkg/minikube/style"
	"k8s.io/minikube/third_party/go9p/ufs"
)

const (
	// nineP is the value of --type used for the 9p filesystem.
	nineP               = "9p"
	defaultMountVersion = "9p2000.L"
	defaultMsize        = 262144
)

// placeholders for flag values
var (
	mountIP      string
	mountPort    uint16
	mountVersion string
	mountType    string
	isKill       bool
	uid          string
	gid          string
	mSize        int
	options      []string
	mode         uint
)

// supportedFilesystems is a map of filesystem types to not warn against.
var supportedFilesystems = map[string]bool{nineP: true}

// mountCmd represents the mount command
var mountCmd = &cobra.Command{
	Use:   "mount [flags] <source directory>:<target directory>",
	Short: "Mounts the specified directory into minikube",
	Long:  `Mounts the specified directory into minikube.`,
	Run: func(cmd *cobra.Command, args []string) {
		if isKill {
			if err := killMountProcess(); err != nil {
				exit.Error(reason.HostKillMountProc, "Error killing mount process", err)
			}
			os.Exit(0)
		}

		if len(args) != 1 {
			exit.Message(reason.Usage, `Please specify the directory to be mounted: 
	minikube mount <source directory>:<target directory>   (example: "/host-home:/vm-home")`)
		}
		mountString := args[0]
		idx := strings.LastIndex(mountString, ":")
		if idx == -1 { // no ":" was present
			exit.Message(reason.Usage, `mount argument "{{.value}}" must be in form: <source directory>:<target directory>`, out.V{"value": mountString})
		}
		hostPath := mountString[:idx]
		vmPath := mountString[idx+1:]
		if _, err := os.Stat(hostPath); err != nil {
			if os.IsNotExist(err) {
				exit.Message(reason.HostPathMissing, "Cannot find directory {{.path}} for mount", out.V{"path": hostPath})
			} else {
				exit.Error(reason.HostPathStat, "stat failed", err)
			}
		}
		if len(vmPath) == 0 || !strings.HasPrefix(vmPath, "/") {
			exit.Message(reason.Usage, "Target directory {{.path}} must be an absolute path", out.V{"path": vmPath})
		}
		var debugVal int
		if klog.V(1).Enabled() {
			debugVal = 1 // ufs.StartServer takes int debug param
		}

		co := mustload.Running(ClusterFlagValue())
		if co.CP.Host.Driver.DriverName() == driver.None {
			exit.Message(reason.Usage, `'none' driver does not support 'minikube mount' command`)
		}

		var ip net.IP
		var err error
		if mountIP == "" {
			if detect.IsMicrosoftWSL() {
				ip, err = func() (net.IP, error) {
					conn, err := net.Dial("udp", "8.8.8.8:80")
					defer conn.Close()
					if err != nil {
						return nil, err
					}
					return conn.LocalAddr().(*net.UDPAddr).IP, nil
				}()
			} else {
				ip, err = cluster.HostIP(co.CP.Host, co.Config.Name)
			}
			if err != nil {
				exit.Error(reason.IfHostIP, "Error getting the host IP address to use from within the VM", err)
			}
		} else {
			ip = net.ParseIP(mountIP)
			if ip == nil {
				exit.Message(reason.IfMountIP, "error parsing the input ip address for mount")
			}
		}
		port, err := getPort()
		if err != nil {<commit_msg>Add logging message incase someone tries to debug.<commit_after>/*
Copyright 2016 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
	"fmt"
	"net"
	"os"
	"os/signal"
	"runtime"
	"strconv"
	"strings"
	"sync"
	"syscall"

	"github.com/pkg/errors"
	"github.com/spf13/cobra"
	"k8s.io/klog/v2"
	"k8s.io/minikube/pkg/minikube/cluster"
	"k8s.io/minikube/pkg/minikube/detect"
	"k8s.io/minikube/pkg/minikube/driver"
	"k8s.io/minikube/pkg/minikube/exit"
	"k8s.io/minikube/pkg/minikube/mustload"
	"k8s.io/minikube/pkg/minikube/out"
	"k8s.io/minikube/pkg/minikube/reason"
	"k8s.io/minikube/pkg/minikube/style"
	"k8s.io/minikube/third_party/go9p/ufs"
)

const (
	// nineP is the value of --type used for the 9p filesystem.
	nineP               = "9p"
	defaultMountVersion = "9p2000.L"
	defaultMsize        = 262144
)

// placeholders for flag values
var (
	mountIP      string
	mountPort    uint16
	mountVersion string
	mountType    string
	isKill       bool
	uid          string
	gid          string
	mSize        int
	options      []string
	mode         uint
)

// supportedFilesystems is a map of filesystem types to not warn against.
var supportedFilesystems = map[string]bool{nineP: true}

// mountCmd represents the mount command
var mountCmd = &cobra.Command{
	Use:   "mount [flags] <source directory>:<target directory>",
	Short: "Mounts the specified directory into minikube",
	Long:  `Mounts the specified directory into minikube.`,
	Run: func(cmd *cobra.Command, args []string) {
		if isKill {
			if err := killMountProcess(); err != nil {
				exit.Error(reason.HostKillMountProc, "Error killing mount process", err)
			}
			os.Exit(0)
		}

		if len(args) != 1 {
			exit.Message(reason.Usage, `Please specify the directory to be mounted: 
	minikube mount <source directory>:<target directory>   (example: "/host-home:/vm-home")`)
		}
		mountString := args[0]
		idx := strings.LastIndex(mountString, ":")
		if idx == -1 { // no ":" was present
			exit.Message(reason.Usage, `mount argument "{{.value}}" must be in form: <source directory>:<target directory>`, out.V{"value": mountString})
		}
		hostPath := mountString[:idx]
		vmPath := mountString[idx+1:]
		if _, err := os.Stat(hostPath); err != nil {
			if os.IsNotExist(err) {
				exit.Message(reason.HostPathMissing, "Cannot find directory {{.path}} for mount", out.V{"path": hostPath})
			} else {
				exit.Error(reason.HostPathStat, "stat failed", err)
			}
		}
		if len(vmPath) == 0 || !strings.HasPrefix(vmPath, "/") {
			exit.Message(reason.Usage, "Target directory {{.path}} must be an absolute path", out.V{"path": vmPath})
		}
		var debugVal int
		if klog.V(1).Enabled() {
			debugVal = 1 // ufs.StartServer takes int debug param
		}

		co := mustload.Running(ClusterFlagValue())
		if co.CP.Host.Driver.DriverName() == driver.None {
			exit.Message(reason.Usage, `'none' driver does not support 'minikube mount' command`)
		}

		var ip net.IP
		var err error
		if mountIP == "" {
			if detect.IsMicrosoftWSL() {
				klog.Infof("Selecting IP for WSL. This may be incorrect...")
				ip, err = func() (net.IP, error) {
					conn, err := net.Dial("udp", "8.8.8.8:80")
					defer conn.Close()
					if err != nil {
						return nil, err
					}
					return conn.LocalAddr().(*net.UDPAddr).IP, nil
				}()
			} else {
				ip, err = cluster.HostIP(co.CP.Host, co.Config.Name)
			}
			if err != nil {
				exit.Error(reason.IfHostIP, "Error getting the host IP address to use from within the VM", err)
			}
		} else {
			ip = net.ParseIP(mountIP)
			if ip == nil {
				exit.Message(reason.IfMountIP, "error parsing the input ip address for mount")
			}
		}
		port, err := getPort()
		if err != nil {
{'fraction_non_alphanumeric': 0.13043478260869565, 'fraction_numerical': 0.012318840579710146, 'mean_word_length': 3.3175182481751824, 'pattern_counts': {'":': 10, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7525007', 'n_tokens_mistral': 3161, 'n_tokens_neox': 2837, 'n_words': 809}