<commit_before>package models

import (
	"fmt"
	"net"
)

// Config ...
type Config struct {
	Provider string `json:"provider"`
	CIMode   bool   `json:"ci-mode"`

	// required for docker-machine
	MountType      string `json:"mount-type"`
	NetfsMountOpts string `json:"netfs-mount-opts"`
	CPUs           int    `json:"cpus"`
	RAM            int    `json:"ram"`
	Disk           int    `json:"disk"`

	// ip address spaces
	ExternalNetworkSpace      string `json:"external-network-space"`
	DockerMachineNetworkSpace string `json:"docker-machine-network-space"`
	NativeNetworkSpace        string `json:"native-network-space"`

	LockPort int `json:"lock-port"`
}

// Save persists the Config to the database
func (c *Config) Save() error {
	// make sure the information in is valid
	c.makeValid()

	// Since there is only ever a single Config value, we'll use the registry
	if err := put("registry", "Config", c); err != nil {
		return fmt.Errorf("failed to save Config: %s", err.Error())
	}

	return nil
}

// set reasonable default values for all necessary values
func (c *Config) makeValid() {
	if c.Provider != "native" && c.Provider != "docker-machine" {
		c.Provider = "docker-machine"
	}

	if c.MountType != "native" && c.MountType != "netfs" {
		c.MountType = "native"
	}

	if c.CPUs == 0 {
		c.CPUs = 1
	}

	if c.RAM == 0 {
		c.RAM = 1
	}

	if c.Disk < 102400 {
		c.Disk = 102400
	}

	if _, _, err := net.ParseCIDR(c.ExternalNetworkSpace); c.ExternalNetworkSpace == "" || err != nil {
		c.ExternalNetworkSpace = "192.168.99.50/24"
	}

	if _, _, err := net.ParseCIDR(c.DockerMachineNetworkSpace); c.DockerMachineNetworkSpace == "" || err != nil {
		c.DockerMachineNetworkSpace = "172.19.0.1/16"
	}

	if _, _, err := net.ParseCIDR(c.NativeNetworkSpace); c.NativeNetworkSpace == "" || err != nil {
		c.NativeNetworkSpace = "172.18.0.1/16"
	}

	if c.LockPort == 0 {
		c.LockPort = 12345
	}
<commit_msg>set a default for netfs on windows fixes #422<commit_after>package models

import (
	"fmt"
	"net"
	"runtime"
)

// Config ...
type Config struct {
	Provider string `json:"provider"`
	CIMode   bool   `json:"ci-mode"`

	// required for docker-machine
	MountType      string `json:"mount-type"`
	NetfsMountOpts string `json:"netfs-mount-opts"`
	CPUs           int    `json:"cpus"`
	RAM            int    `json:"ram"`
	Disk           int    `json:"disk"`

	// ip address spaces
	ExternalNetworkSpace      string `json:"external-network-space"`
	DockerMachineNetworkSpace string `json:"docker-machine-network-space"`
	NativeNetworkSpace        string `json:"native-network-space"`

	LockPort int `json:"lock-port"`
}

// Save persists the Config to the database
func (c *Config) Save() error {
	// make sure the information in is valid
	c.makeValid()

	// Since there is only ever a single Config value, we'll use the registry
	if err := put("registry", "Config", c); err != nil {
		return fmt.Errorf("failed to save Config: %s", err.Error())
	}

	return nil
}

// set reasonable default values for all necessary values
func (c *Config) makeValid() {
	if c.Provider != "native" && c.Provider != "docker-machine" {
		c.Provider = "docker-machine"
	}

	if c.MountType != "native" && c.MountType != "netfs" {
		c.MountType = "native"
	}

	if c.CPUs == 0 {
		c.CPUs = 1
	}

	if c.RAM == 0 {
		c.RAM = 1
	}

	if c.Disk < 102400 {
		c.Disk = 102400
	}

	if c.NetfsMountOpts == "" && runtime.GOOS == "windows" {
		c.NetfsMountOpts = "mfsymlinks"
	}

	if _, _, err := net.ParseCIDR(c.ExternalNetworkSpace); c.ExternalNetworkSpace == "" || err != nil {
		c.ExternalNetworkSpace = "192.168.99.50/24"
	}

	if _, _, err := net.ParseCIDR(c.DockerMachineNetworkSpace); c.DockerMachineNetworkSpace == "" || err != nil {
		c.DockerMachineNetworkSpace = "172.19.0.1/16"
	}

	if _, _, err := net.ParseCIDR(c.NativeNetworkSpace); c.NativeNetworkSpace == "" || err != nil {
		c.NativeNetworkSpace = "172.18.0.1/16"
	}

	if c.LockPort == 0 {
		c.LockPort = 12345
	}

{'fraction_non_alphanumeric': 0.1519918802334433, 'fraction_numerical': 0.02715046942400406, 'mean_word_length': 3.1936170212765957, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, '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': '7272586', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1358, 'n_words': 349}