File: copy_and_wait.go

package info (click to toggle)
golang-github-tombuildsstuff-giovanni 0.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 15,908 kB
  • sloc: makefile: 3
file content (41 lines) | stat: -rw-r--r-- 1,064 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package blobs

import (
	"context"
	"fmt"
	"time"
)

// CopyAndWait copies a blob to a destination within the storage account and waits for it to finish copying.
func (client Client) CopyAndWait(ctx context.Context, accountName, containerName, blobName string, input CopyInput, pollingInterval time.Duration) error {
	if _, err := client.Copy(ctx, accountName, containerName, blobName, input); err != nil {
		return fmt.Errorf("Error copying: %s", err)
	}

	for true {
		getInput := GetPropertiesInput{
			LeaseID: input.LeaseID,
		}
		getResult, err := client.GetProperties(ctx, accountName, containerName, blobName, getInput)
		if err != nil {
			return fmt.Errorf("")
		}

		switch getResult.CopyStatus {
		case Aborted:
			return fmt.Errorf("Copy was aborted: %s", getResult.CopyStatusDescription)

		case Failed:
			return fmt.Errorf("Copy failed: %s", getResult.CopyStatusDescription)

		case Success:
			return nil

		case Pending:
			time.Sleep(pollingInterval)
			continue
		}
	}

	return fmt.Errorf("Unexpected error waiting for the copy to complete")
}