add directory existence check
This commit is contained in:
parent
7fac596b37
commit
19bd997f11
|
@ -69,8 +69,11 @@ func (s *StepRemoteUpload) uploadFile(path string, d driver.Driver, ui packer.Ui
|
|||
|
||||
ui.Say(fmt.Sprintf("Uploading %s to %s", filename, remotePath))
|
||||
|
||||
if err := ds.MakeDirectory(remoteDirectory); err != nil {
|
||||
return "", err
|
||||
if exists := ds.DirExists(remotePath); exists == false {
|
||||
log.Printf("Remote directory doesn't exist; creating...")
|
||||
if err := ds.MakeDirectory(remoteDirectory); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
if err := ds.UploadFile(path, remotePath, s.Host, s.SetHostForDatastoreUploads); err != nil {
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
type Datastore interface {
|
||||
Info(params ...string) (*mo.Datastore, error)
|
||||
FileExists(path string) bool
|
||||
DirExists(path string) bool
|
||||
Name() string
|
||||
ResolvePath(path string) string
|
||||
UploadFile(src, dst, host string, setHost bool) error
|
||||
|
@ -102,6 +103,14 @@ func (ds *DatastoreDriver) Info(params ...string) (*mo.Datastore, error) {
|
|||
return &info, nil
|
||||
}
|
||||
|
||||
func (ds *DatastoreDriver) DirExists(filepath string) bool {
|
||||
_, err := ds.ds.Stat(ds.driver.ctx, filepath)
|
||||
if _, ok := err.(object.DatastoreNoSuchDirectoryError); ok {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (ds *DatastoreDriver) FileExists(path string) bool {
|
||||
_, err := ds.ds.Stat(ds.driver.ctx, path)
|
||||
return err == nil
|
||||
|
|
|
@ -37,6 +37,9 @@ func (ds *DatastoreMock) FileExists(path string) bool {
|
|||
return ds.FileExistsReturn
|
||||
}
|
||||
|
||||
func (ds *DatastoreMock) DirExists(path string) bool {
|
||||
return true
|
||||
}
|
||||
func (ds *DatastoreMock) Name() string {
|
||||
if ds.NameReturn == "" {
|
||||
return "datastore-mock"
|
||||
|
|
Loading…
Reference in New Issue