Remove remote cache correctly.

This commit is contained in:
Matthew Hooker 2018-04-26 10:56:48 -07:00
parent 451e3d0554
commit 97cfd60b82
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
4 changed files with 13 additions and 13 deletions

View File

@ -138,6 +138,12 @@ func (d *ESX5Driver) UploadISO(localPath string, checksum string, checksumType s
return finalPath, nil
}
func (d *ESX5Driver) RemoveCache(localPath string) error {
finalPath := filepath.ToSlash(filepath.Dir(d.cachePath(localPath)))
log.Printf("Removing remote cache path %s (local %s)", finalPath, localPath)
return d.sh("rm", "-rf", finalPath)
}
func (d *ESX5Driver) ToolsIsoPath(string) string {
return ""
}
@ -569,10 +575,6 @@ func (d *ESX5Driver) mkdir(path string) error {
return d.sh("mkdir", "-p", path)
}
func (d *ESX5Driver) remove(path string) error {
return d.sh("rm", "-rf", path)
}
func (d *ESX5Driver) upload(dst, src string) error {
f, err := os.Open(src)
if err != nil {

View File

@ -12,6 +12,9 @@ type RemoteDriver interface {
// exists.
UploadISO(string, string, string) (string, error)
// RemoveCache deletes localPath from the remote cache.
RemoveCache(localPath string) error
// Adds a VM to inventory specified by the path to the VMX given.
Register(string) error
@ -27,9 +30,6 @@ type RemoteDriver interface {
// Uploads a local file to remote side.
upload(dst, src string) error
// Forcefully remove a path from the remote side.
remove(path string) error
// Reload VM on remote side.
ReloadVM() error
}

View File

@ -61,11 +61,11 @@ func (d *RemoteDriverMock) IsDestroyed() (bool, error) {
}
func (d *RemoteDriverMock) upload(dst, src string) error {
return nil
return d.uploadErr
}
func (d *RemoteDriverMock) remove(path string) error {
return d.uploadErr
func (d *RemoteDriverMock) RemoveCache(localPath string) error {
return nil
}
func (d *RemoteDriverMock) ReloadVM() error {

View File

@ -56,7 +56,6 @@ func (s *stepRemoteUpload) Cleanup(state multistep.StateBag) {
}
driver := state.Get("driver").(vmwcommon.Driver)
// ui := state.Get("ui").(packer.Ui)
remote, ok := driver.(RemoteDriver)
if !ok {
@ -69,9 +68,8 @@ func (s *stepRemoteUpload) Cleanup(state multistep.StateBag) {
}
log.Printf("Cleaning up remote path: %s", path)
err := remote.remove(path)
err := remote.RemoveCache(path)
if err != nil {
log.Printf("Error cleaning up: %s", err)
}
}