-
Notifications
You must be signed in to change notification settings - Fork 26
/
createdir.go
72 lines (62 loc) · 1.54 KB
/
createdir.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
package allocationchange
import (
"fmt"
"path"
"strings"
"github.com/0chain/gosdk/core/common"
"github.com/0chain/gosdk/core/util"
"github.com/0chain/gosdk/zboxcore/fileref"
"github.com/google/uuid"
)
type DirCreateChange struct {
Timestamp common.Timestamp
RemotePath string
Uuid uuid.UUID
}
func (d *DirCreateChange) ProcessChange(rootRef *fileref.Ref, FileIDMeta map[string]string) (err error) {
fields, err := common.GetPathFields(d.RemotePath)
if err != nil {
return
}
dirRef := rootRef
for i := 0; i < len(fields); i++ {
found := false
for _, child := range dirRef.Children {
if child.GetName() == fields[i] {
ref, ok := child.(*fileref.Ref)
if !ok {
err = fmt.Errorf(
"invalid_ref: Expected type *fileref.Ref but got %T for"+
" file name: %s, file path: %s, file type: %s",
child, child.GetName(), child.GetPath(), child.GetType())
return
}
dirRef = ref
found = true
break
}
}
if !found {
uid := util.GetSHA1Uuid(d.Uuid, fields[i])
d.Uuid = uid
newRef := &fileref.Ref{
Type: fileref.DIRECTORY,
AllocationID: dirRef.AllocationID,
Path: path.Join("/", strings.Join(fields[:i+1], "/")),
Name: fields[i],
FileID: uid.String(),
}
FileIDMeta[newRef.Path] = newRef.FileID
newRef.HashToBeComputed = true
dirRef.AddChild(newRef)
dirRef = newRef
}
}
return
}
func (d *DirCreateChange) GetAffectedPath() []string {
return []string{d.RemotePath}
}
func (d *DirCreateChange) GetSize() int64 {
return 0
}