diff --git a/pkg/common/common.go b/pkg/common/common.go index 2fde2ef..c62484d 100644 --- a/pkg/common/common.go +++ b/pkg/common/common.go @@ -23,6 +23,7 @@ import ( "path/filepath" "syscall" + "github.com/docker/go-units" "github.com/docker/machine/libmachine/drivers" "github.com/docker/machine/libmachine/mcnflag" "github.com/docker/machine/libmachine/mcnutils" @@ -52,6 +53,12 @@ func (d *CommonDriver) SetConfigFromFlags(flags drivers.DriverOptions) error { return nil } +func diskSizeInMiB(diskSizeMB int) int64 { + result := int64(diskSizeMB) + result *= units.MiB + return result +} + func createRawDiskImage(sshKeyPath, diskPath string, diskSizeMb int) error { tarBuf, err := mcnutils.MakeDiskImage(sshKeyPath) if err != nil { @@ -74,7 +81,7 @@ func createRawDiskImage(sshKeyPath, diskPath string, diskSizeMb int) error { return errors.Wrapf(err, "closing file %s", diskPath) } - if err := os.Truncate(diskPath, int64(diskSizeMb*1000000)); err != nil { + if err := os.Truncate(diskPath, diskSizeInMiB(diskSizeMb)); err != nil { return errors.Wrap(err, "truncate") } return nil diff --git a/pkg/common/common_test.go b/pkg/common/common_test.go index cc250e0..14cc631 100644 --- a/pkg/common/common_test.go +++ b/pkg/common/common_test.go @@ -36,7 +36,7 @@ func Test_createDiskImage(t *testing.T) { diskPath := filepath.Join(tmpdir, "disk") sizeInMb := 100 - sizeInBytes := int64(sizeInMb) * 1000000 + sizeInBytes := int64(104857600) if err := createRawDiskImage(sshPath, diskPath, sizeInMb); err != nil { t.Errorf("createDiskImage() error = %v", err) }