From 27c19af9ff85361220d0d6e02b737c80c103ec5e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 22 Dec 2016 16:47:32 -0800 Subject: [PATCH] provisioners/file: support Stop --- .../provisioners/file/resource_provisioner.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/builtin/provisioners/file/resource_provisioner.go b/builtin/provisioners/file/resource_provisioner.go index 71fde06105..001e78af52 100644 --- a/builtin/provisioners/file/resource_provisioner.go +++ b/builtin/provisioners/file/resource_provisioner.go @@ -58,9 +58,23 @@ func applyFn(ctx context.Context) error { defer os.Remove(src) } - // Get destination + // Begin the file copy dst := data.Get("destination").(string) - return copyFiles(comm, src, dst) + resultCh := make(chan error, 1) + go func() { + resultCh <- copyFiles(comm, src, dst) + }() + + // Allow the file copy to complete unless there is an interrupt. + // If there is an interrupt we make no attempt to cleanly close + // the connection currently. We just abruptly exit. Because Terraform + // taints the resource, this is fine. + select { + case err := <-resultCh: + return err + case <-ctx.Done(): + return fmt.Errorf("file transfer interrupted") + } } // getSrc returns the file to use as source