func()

in gke-windows-builder/builder/builder/remote.go [72:119]


func (r *RemoteWindowsServer) Copy(inputPath string, copyTimeout time.Duration) error {
	defer func() {
		// Flush stdout
		fmt.Println()
	}()

	if copyTimeout <= 0 {
		return errors.New("copy timeout must be greater than 0")
	}

	hostport := fmt.Sprintf("%s:5986", *r.Hostname)
	c, err := winrmcp.New(hostport, &winrmcp.Config{
		Auth:                  winrmcp.Auth{User: *r.Username, Password: *r.Password},
		Https:                 true,
		Insecure:              true,
		TLSServerName:         "",
		CACertBytes:           nil,
		OperationTimeout:      copyTimeout,
		MaxOperationsPerShell: 15,
	})
	if err != nil {
		log.Printf("Error creating connection to remote for copy: %+v", err)
		return err
	}

	// First try to create a bucket and have the Windows VM download it via a
	// GS URL. If that fails, use the remote copy method.
	err = r.copyViaBucket(
		context.Background(),
		inputPath,
		copyTimeout,
	)
	if err == nil {
		// Successfully copied via GCE bucket
		log.Printf("Successfully copied data via GCE bucket to %s", *r.WorkspaceFolder)
		return nil
	}

	log.Printf("Failed to copy data via GCE bucket: %v", err)

	err = c.Copy(inputPath, *r.WorkspaceFolder)
	if err != nil {
		log.Printf("Error copying workspace to remote: %+v", err)
		return err
	}

	return nil
}