diff --git a/builder/parallels/common/driver.go b/builder/parallels/common/driver.go index 81b7cd974..e6a5b7bb1 100644 --- a/builder/parallels/common/driver.go +++ b/builder/parallels/common/driver.go @@ -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) diff --git a/builder/parallels/common/driver_9.go b/builder/parallels/common/driver_9.go index 1093351c8..2c7f2fc2f 100644 --- a/builder/parallels/common/driver_9.go +++ b/builder/parallels/common/driver_9.go @@ -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, diff --git a/builder/parallels/common/driver_mock.go b/builder/parallels/common/driver_mock.go index fc43247f5..fcd6b4b88 100644 --- a/builder/parallels/common/driver_mock.go +++ b/builder/parallels/common/driver_mock.go @@ -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