func (client *clientImpl) FetchAndDeployInstance(pin common.Pin) error { err := common.ValidatePin(pin) if err != nil { return err } // Use temp file for storing package file. Delete it when done. var instance local.PackageInstance f, err := client.deployer.TempFile(pin.InstanceID) if err != nil { return err } defer func() { // Instance takes ownership of the file, no need to close it separately. if instance == nil { f.Close() } os.Remove(f.Name()) }() // Fetch the package data to the provided storage. err = client.FetchInstance(pin, f) if err != nil { return err } // Open the instance, verify the instance ID. instance, err = local.OpenInstance(f, pin.InstanceID) if err != nil { return err } defer instance.Close() // Deploy it. 'defer' will take care of removing the temp file if needed. _, err = client.deployer.DeployInstance(instance) return err }