builder/parallels: Add "CompactDisk" driver function

This function compacts the specified virtual disk image.
This commit is contained in:
Mikhail Zholobov 2015-06-21 13:34:35 +03:00
parent 4ebee7bf3f
commit f7b26e44fe
3 changed files with 40 additions and 0 deletions

View File

@ -15,6 +15,9 @@ import (
// versions out of the builder steps, so sometimes the methods are
// extremely specific.
type Driver interface {
// Compact a virtual disk image.
CompactDisk(string) error
// Adds new CD/DVD drive to the VM and returns name of this device
DeviceAddCdRom(string, string) (string, error)

View File

@ -98,6 +98,33 @@ func getAppPath(bundleId string) (string, error) {
return pathOutput, nil
}
func (d *Parallels9Driver) CompactDisk(diskPath string) error {
prlDiskToolPath, err := exec.LookPath("prl_disk_tool")
if err != nil {
return err
}
// Analyze the disk content and remove unused blocks
command := []string{
"compact",
"--hdd", diskPath,
}
if err := exec.Command(prlDiskToolPath, command...).Run(); err != nil {
return err
}
// Remove null blocks
command = []string{
"compact", "--buildmap",
"--hdd", diskPath,
}
if err := exec.Command(prlDiskToolPath, command...).Run(); err != nil {
return err
}
return nil
}
func (d *Parallels9Driver) DeviceAddCdRom(name string, image string) (string, error) {
command := []string{
"set", name,

View File

@ -5,6 +5,10 @@ import "sync"
type DriverMock struct {
sync.Mutex
CompactDiskCalled bool
CompactDiskPath string
CompactDiskErr error
DeviceAddCdRomCalled bool
DeviceAddCdRomName string
DeviceAddCdRomImage string
@ -59,6 +63,12 @@ type DriverMock struct {
IpAddressError error
}
func (d *DriverMock) CompactDisk(path string) error {
d.CompactDiskCalled = true
d.CompactDiskPath = path
return d.CompactDiskErr
}
func (d *DriverMock) DeviceAddCdRom(name string, image string) (string, error) {
d.DeviceAddCdRomCalled = true
d.DeviceAddCdRomName = name