use strconv.Quote instead of fmt.Sprint

This commit is contained in:
Megan Marsh 2018-10-22 10:45:54 -07:00
parent 7d40aeaa33
commit fd8a85042d
1 changed files with 11 additions and 10 deletions

View File

@ -11,6 +11,7 @@ import (
"net"
"os"
"path/filepath"
"strconv"
"strings"
"time"
@ -47,11 +48,11 @@ func (d *ESX5Driver) Clone(dst, src string, linked bool) error {
func (d *ESX5Driver) CompactDisk(diskPathLocal string) error {
diskPath := d.datastorePath(diskPathLocal)
return d.sh("vmkfstools", "--punchzero", fmt.Sprintf("\"%s\"", diskPath))
return d.sh("vmkfstools", "--punchzero", strconv.Quote(diskPath))
}
func (d *ESX5Driver) CreateDisk(diskPathLocal string, size string, adapter_type string, typeId string) error {
diskPath := fmt.Sprintf("\"%s\"", d.datastorePath(diskPathLocal))
diskPath := strconv.Quote(d.datastorePath(diskPathLocal))
return d.sh("vmkfstools", "-c", size, "-d", typeId, "-a", adapter_type, diskPath)
}
@ -92,7 +93,7 @@ func (d *ESX5Driver) Register(vmxPathLocal string) error {
if err := d.upload(vmxPath, vmxPathLocal); err != nil {
return err
}
r, err := d.run(nil, "vim-cmd", "solo/registervm", fmt.Sprintf("\"%s\"", vmxPath))
r, err := d.run(nil, "vim-cmd", "solo/registervm", strconv.Quote(vmxPath))
if err != nil {
return err
}
@ -113,7 +114,7 @@ func (d *ESX5Driver) Destroy() error {
}
func (d *ESX5Driver) IsDestroyed() (bool, error) {
err := d.sh("test", "!", "-e", fmt.Sprintf("\"%s\"", d.outputDir))
err := d.sh("test", "!", "-e", strconv.Quote(d.outputDir))
if err != nil {
return false, err
}
@ -142,7 +143,7 @@ func (d *ESX5Driver) UploadISO(localPath string, checksum string, checksumType s
func (d *ESX5Driver) RemoveCache(localPath string) error {
finalPath := d.cachePath(localPath)
log.Printf("Removing remote cache path %s (local %s)", finalPath, localPath)
return d.sh("rm", "-f", fmt.Sprintf("\"%s\"", finalPath))
return d.sh("rm", "-f", strconv.Quote(finalPath))
}
func (d *ESX5Driver) ToolsIsoPath(string) string {
@ -450,7 +451,7 @@ func (d *ESX5Driver) CommHost(state multistep.StateBag) (string, error) {
//-------------------------------------------------------------------
func (d *ESX5Driver) DirExists() (bool, error) {
err := d.sh("test", "-e", fmt.Sprintf("\"%s\"", d.outputDir))
err := d.sh("test", "-e", strconv.Quote(d.outputDir))
return err == nil, nil
}
@ -482,11 +483,11 @@ func (d *ESX5Driver) MkdirAll() error {
}
func (d *ESX5Driver) Remove(path string) error {
return d.sh("rm", fmt.Sprintf("\"%s\"", path))
return d.sh("rm", strconv.Quote(path))
}
func (d *ESX5Driver) RemoveAll() error {
return d.sh("rm", "-rf", fmt.Sprintf("\"%s\"", d.outputDir))
return d.sh("rm", "-rf", strconv.Quote(d.outputDir))
}
func (d *ESX5Driver) SetOutputDir(path string) {
@ -579,7 +580,7 @@ func (d *ESX5Driver) checkGuestIPHackEnabled() error {
}
func (d *ESX5Driver) mkdir(path string) error {
return d.sh("mkdir", "-p", fmt.Sprintf("\"%s\"", path))
return d.sh("mkdir", "-p", strconv.Quote(path))
}
func (d *ESX5Driver) upload(dst, src string) error {
@ -593,7 +594,7 @@ func (d *ESX5Driver) upload(dst, src string) error {
func (d *ESX5Driver) verifyChecksum(ctype string, hash string, file string) bool {
if ctype == "none" {
if err := d.sh("stat", fmt.Sprintf("\"%s\"", file)); err != nil {
if err := d.sh("stat", strconv.Quote(file)); err != nil {
return false
}
} else {