<commit_before>package main

import (
	"flag"
	"fmt"
	"log"
	"path/filepath"
	"sync"

	"github.com/appropriate/go-virtualboxclient/virtualboxclient"
	"github.com/calavera/dkvolume"
)

const (
	defaultVboxwebsrvUrl = "http://192.168.99.1:18083"
)

var (
	vboxwebsrvUsername = flag.String("vboxwebsrv-username", "", "Username to connect to vboxwebsrv")
	vboxwebsrvPassword = flag.String("vboxwebsrv-password", "", "Password to connect to vboxwebsrv")
	vboxwebsrvUrl      = flag.String("vboxwebsrv-url", defaultVboxwebsrvUrl, "URL to connect to vboxwebsrv")
)

type virtualboxDriver struct {
	sync.Mutex

	client  *virtualboxclient.VirtualBoxClient
	volumes map[string]*virtualboxclient.Medium
}

func (d virtualboxDriver) Create(r dkvolume.Request) dkvolume.Response {
	d.Lock()
	defer d.Unlock()

	var err error

	fmt.Printf("Creating volume %#v\n", r)

	var medium *virtualboxclient.Medium
	if medium, err = d.client.CreateHardDisk("vmdk", d.storageLocation(r.Name)); err != nil {
		return dkvolume.Response{Err: err.Error()}
	}

	fmt.Printf("Hard disk: %#v\n", medium)

	if _, err = medium.CreateBaseStorage(1000000, nil); err != nil {
		return dkvolume.Response{Err: err.Error()}
	}

	d.volumes[r.Name] = medium

	return dkvolume.Response{}
}

func (d virtualboxDriver) Mount(r dkvolume.Request) dkvolume.Response {
	fmt.Printf("Mounting volume %#v\n", r)
	return dkvolume.Response{}
}

func (d virtualboxDriver) Path(r dkvolume.Request) dkvolume.Response {
	fmt.Printf("Pathing volume %#v\n", r)
	return dkvolume.Response{}
}

func (d virtualboxDriver) Remove(r dkvolume.Request) dkvolume.Response {
	d.Lock()
	defer d.Unlock()

	fmt.Printf("Removing volume %#v\n", r)

	if m, ok := d.volumes[r.Name]; ok {
		if _, err := m.DeleteStorage(); err != nil {
			return dkvolume.Response{Err: err.Error()}
		}
	}

	return dkvolume.Response{}
}

func (d virtualboxDriver) Unmount(r dkvolume.Request) dkvolume.Response {
	fmt.Printf("Unmounting volume %#v\n", r)
	return dkvolume.Response{}
}

func (d virtualboxDriver) storageLocation(name string) string {
	return filepath.Join("/Users/mike/.docker/machine/machines/dev", fmt.Sprintf("%s.vmdk", name))
}

// TODO: Figure out why Ctrl+C doesn't immediately terminate
func main() {
	flag.Parse()

	client := virtualboxclient.New(*vboxwebsrvUsername, *vboxwebsrvPassword, *vboxwebsrvUrl)

	if err := client.Logon(); err != nil {
		log.Fatal(err)
	}

	d := virtualboxDriver{
		client:  client,
		volumes: map[string]*virtualboxclient.Medium{},
	}
	h := dkvolume.NewHandler(d)
	fmt.Println(h.ServeUnix("root", "virtualbox"))
}<commit_msg>Make mount root configurable<commit_after>package main

import (
	"flag"
	"fmt"
	"log"
	"path/filepath"
	"sync"

	"github.com/appropriate/go-virtualboxclient/virtualboxclient"
	"github.com/calavera/dkvolume"
)

const (
	pluginId = "virtualbox"

	defaultVboxwebsrvUrl = "http://192.168.99.1:18083"
)

var (
	socketAddress    = filepath.Join("/run/docker/plugins", fmt.Sprintf("%s.sock", pluginId))
	defaultMountRoot = filepath.Join(dkvolume.DefaultDockerRootDirectory, fmt.Sprintf("_%s", pluginId))
	mountRoot        = flag.String("mount-root", defaultMountRoot, "VirtualBox volumes root mount directory")

	vboxwebsrvUsername = flag.String("vboxwebsrv-username", "", "Username to connect to vboxwebsrv")
	vboxwebsrvPassword = flag.String("vboxwebsrv-password", "", "Password to connect to vboxwebsrv")
	vboxwebsrvUrl      = flag.String("vboxwebsrv-url", defaultVboxwebsrvUrl, "URL to connect to vboxwebsrv")
)

type virtualboxDriver struct {
	sync.Mutex

	client  *virtualboxclient.VirtualBoxClient
	volumes map[string]*virtualboxclient.Medium
}

func (d virtualboxDriver) Create(r dkvolume.Request) dkvolume.Response {
	d.Lock()
	defer d.Unlock()

	var err error

	fmt.Printf("Creating volume %#v\n", r)

	var medium *virtualboxclient.Medium
	if medium, err = d.client.CreateHardDisk("vmdk", d.storageLocation(r.Name)); err != nil {
		return dkvolume.Response{Err: err.Error()}
	}

	fmt.Printf("Hard disk: %#v\n", medium)

	if _, err = medium.CreateBaseStorage(1000000, nil); err != nil {
		return dkvolume.Response{Err: err.Error()}
	}

	d.volumes[r.Name] = medium

	return dkvolume.Response{}
}

func (d virtualboxDriver) Mount(r dkvolume.Request) dkvolume.Response {
	fmt.Printf("Mounting volume %#v\n", r)
	return dkvolume.Response{}
}

func (d virtualboxDriver) Path(r dkvolume.Request) dkvolume.Response {
	fmt.Printf("Pathing volume %#v\n", r)
	return dkvolume.Response{}
}

func (d virtualboxDriver) Remove(r dkvolume.Request) dkvolume.Response {
	d.Lock()
	defer d.Unlock()

	fmt.Printf("Removing volume %#v\n", r)

	if m, ok := d.volumes[r.Name]; ok {
		if _, err := m.DeleteStorage(); err != nil {
			return dkvolume.Response{Err: err.Error()}
		}
	}

	return dkvolume.Response{}
}

func (d virtualboxDriver) Unmount(r dkvolume.Request) dkvolume.Response {
	fmt.Printf("Unmounting volume %#v\n", r)
	return dkvolume.Response{}
}

func (d virtualboxDriver) storageLocation(name string) string {
	return filepath.Join("/Users/mike/.docker/machine/machines/dev", fmt.Sprintf("%s.vmdk", name))
}

// TODO: Figure out why Ctrl+C doesn't immediately terminate
func main() {
	flag.Parse()

	client := virtualboxclient.New(*vboxwebsrvUsername, *vboxwebsrvPassword, *vboxwebsrvUrl)

	if err := client.Logon(); err != nil {
		log.Fatal(err)
	}

	d := virtualboxDriver{
		client:  client,
		volumes: map[string]*virtualboxclient.Medium{},
	}
	h := dkvolume.NewHandler(d)
	fmt.Printf("Listening on %s\n", socketAddress)
	fmt.Println(h.ServeUnix("root", socketAddress))
}
{'fraction_non_alphanumeric': 0.14612612612612613, 'fraction_numerical': 0.0075675675675675675, 'mean_word_length': 4.943254817987152, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1898490', 'n_tokens_mistral': 2094, 'n_tokens_neox': 1986, 'n_words': 415}