MCPcopy Create free account
hub / github.com/MG-RAST/Shock / addPart

Method addPart

shock-server/node/parts.go:85–116  ·  view source on GitHub ↗
(n int, file *file.FormFile)

Source from the content-addressed store, hash-verified

83}
84
85func (node *Node) addPart(n int, file *file.FormFile) (err error) {
86 if n >= node.Parts.Count && !node.Parts.VarLen {
87 return errors.New("part number is greater than node length: " + strconv.Itoa(node.Parts.Length))
88 }
89
90 if n < node.Parts.Count && len(node.Parts.Parts[n]) > 0 {
91 return errors.New(e.FileImut)
92 }
93
94 // create part
95 part := partsFile{file.Name, file.Checksum["md5"]}
96
97 // add part to node
98 if node.Parts.VarLen == true && n >= node.Parts.Count {
99 for i := node.Parts.Count; i < n; i = i + 1 {
100 node.Parts.Parts = append(node.Parts.Parts, partsFile{})
101 node.Parts.Count = node.Parts.Count + 1
102 }
103 node.Parts.Parts = append(node.Parts.Parts, part)
104 node.Parts.Count = node.Parts.Count + 1
105 node.Parts.Length = node.Parts.Length + 1
106 } else {
107 node.Parts.Parts[n] = part
108 node.Parts.Length = node.Parts.Length + 1
109 }
110
111 // put part into data directory
112 if err = os.Rename(file.Path, fmt.Sprintf("%s/parts/%d", node.Path(), n+1)); err != nil {
113 return err
114 }
115 return
116}
117
118func (node *Node) closeParts(allowEmpty bool) (err error) {
119 // Second param says we will allow empty parts in merging of those parts, true for variable length parts

Callers 1

UpdateMethod · 0.95

Calls 1

PathMethod · 0.95

Tested by

no test coverage detected