-
Notifications
You must be signed in to change notification settings - Fork 86
/
multipart.go
85 lines (80 loc) · 1.74 KB
/
multipart.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
package meta
import (
"database/sql"
. "github.com/journeymidnight/yig/meta/types"
)
func (m *Meta) GetMultipart(bucketName, objectName, uploadId string) (multipart Multipart, err error) {
return m.Client.GetMultipart(bucketName, objectName, uploadId)
}
func (m *Meta) DeleteMultipart(multipart Multipart) (err error) {
tx, err := m.Client.NewTrans()
if err != nil {
return err
}
defer func() {
if err != nil {
m.Client.AbortTrans(tx)
}
}()
err = m.Client.DeleteMultipart(&multipart, tx)
if err != nil {
return
}
var removedSize int64 = 0
for _, p := range multipart.Parts {
removedSize += p.Size
}
err = m.Client.UpdateUsage(multipart.BucketName, -removedSize, tx)
if err != nil {
return
}
err = m.Client.CommitTrans(tx)
return
}
func (m *Meta) PutObjectPart(multipart Multipart, part Part) (err error) {
tx, err := m.Client.NewTrans()
if err != nil {
return err
}
defer func() {
if err != nil {
m.Client.AbortTrans(tx)
}
}()
err = m.Client.PutObjectPart(&multipart, &part, tx)
if err != nil {
return
}
var removedSize int64 = 0
if part, ok := multipart.Parts[part.PartNumber]; ok {
removedSize += part.Size
}
err = m.Client.UpdateUsage(multipart.BucketName, part.Size-removedSize, tx)
if err != nil {
return
}
err = m.Client.CommitTrans(tx)
return
}
func (m *Meta) RenameObjectPart(object *Object, sourceObject string) (err error) {
var tx *sql.Tx
tx, err = m.Client.NewTrans()
if err != nil {
return err
}
defer func() {
if err != nil {
m.Client.AbortTrans(tx)
}
}()
err = m.Client.RenameObjectPart(object, sourceObject, tx)
if err != nil {
return err
}
err = m.Client.RenameObject(object, sourceObject, tx)
if err != nil {
return err
}
err = m.Client.CommitTrans(tx)
return err
}