-
Notifications
You must be signed in to change notification settings - Fork 22
/
copy_abort.go
98 lines (80 loc) · 2.03 KB
/
copy_abort.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package files
import (
"context"
"fmt"
"net/http"
"strings"
"github.com/hashicorp/go-azure-sdk/sdk/client"
"github.com/hashicorp/go-azure-sdk/sdk/odata"
)
type CopyAbortInput struct {
copyID string
}
type CopyAbortResponse struct {
HttpResponse *http.Response
}
// AbortCopy aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata
func (c Client) AbortCopy(ctx context.Context, shareName, path, fileName string, input CopyAbortInput) (result CopyAbortResponse, err error) {
if shareName == "" {
err = fmt.Errorf("`shareName` cannot be an empty string")
return
}
if strings.ToLower(shareName) != shareName {
err = fmt.Errorf("`shareName` must be a lower-cased string")
return
}
if fileName == "" {
err = fmt.Errorf("`fileName` cannot be an empty string")
return
}
if input.copyID == "" {
err = fmt.Errorf("`copyID` cannot be an empty string")
return
}
if path != "" {
path = fmt.Sprintf("%s/", path)
}
opts := client.RequestOptions{
ContentType: "application/xml; charset=utf-8",
ExpectedStatusCodes: []int{
http.StatusNoContent,
},
HttpMethod: http.MethodPut,
OptionsObject: CopyAbortOptions{
copyId: input.copyID,
},
Path: fmt.Sprintf("/%s/%s%s", shareName, path, fileName),
}
req, err := c.Client.NewRequest(ctx, opts)
if err != nil {
err = fmt.Errorf("building request: %+v", err)
return
}
var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
err = fmt.Errorf("executing request: %+v", err)
return
}
return
}
type CopyAbortOptions struct {
copyId string
}
func (c CopyAbortOptions) ToHeaders() *client.Headers {
headers := &client.Headers{}
headers.Append("x-ms-copy-action", "abort")
return headers
}
func (c CopyAbortOptions) ToOData() *odata.Query {
return nil
}
func (c CopyAbortOptions) ToQuery() *client.QueryParams {
out := &client.QueryParams{}
out.Append("comp", "copy")
out.Append("copyid", c.copyId)
return out
}