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

Function CreateNodesFromArchive

shock-server/node/node.go:155–241  ·  view source on GitHub ↗
(u *user.User, params map[string]string, files file.FormFiles, archiveId string)

Source from the content-addressed store, hash-verified

153}
154
155func CreateNodesFromArchive(u *user.User, params map[string]string, files file.FormFiles, archiveId string) (nodes []*Node, err error) {
156 // get parent node
157 archiveNode, err := Load(archiveId)
158 if err != nil {
159 return nil, err
160 }
161 if archiveNode.File.Size == 0 {
162 return nil, errors.New("parent archive node has no file")
163 }
164
165 // get format
166 aFormat, hasFormat := params["archive_format"]
167 if !hasFormat {
168 return nil, errors.New("missing archive_format parameter. use one of: " + archive.ArchiveList)
169 }
170 if !archive.IsValidArchive(aFormat) {
171 return nil, errors.New("invalid archive_format parameter. use one of: " + archive.ArchiveList)
172 }
173
174 // get attributes
175 var atttributes interface{}
176 if attrFile, ok := files["attributes"]; ok {
177 defer attrFile.Remove()
178 attr, err := ioutil.ReadFile(attrFile.Path)
179 if err != nil {
180 return nil, err
181 }
182 if err = json.Unmarshal(attr, &atttributes); err != nil {
183 return nil, err
184 }
185 } else if attrStr, ok := params["attributes_str"]; ok {
186 if err = json.Unmarshal([]byte(attrStr), &atttributes); err != nil {
187 return nil, err
188 }
189 }
190
191 // get files / delete unpack dir when done
192 fileList, unpackDir, err := archive.FilesFromArchive(aFormat, archiveNode.FilePath())
193 defer os.RemoveAll(unpackDir)
194 if err != nil {
195 return nil, err
196 }
197
198 // preserve acls
199 _, preserveAcls := params["preserve_acls"]
200
201 // build nodes
202 var tempNodes []*Node
203 for _, f := range fileList {
204 // create link
205 link := linkage{Type: "parent", Operation: aFormat, Ids: []string{archiveId}}
206 // create and populate node
207 node := New()
208 node.Type = "basic"
209 node.Linkages = append(node.Linkages, link)
210 node.Attributes = atttributes
211
212 if preserveAcls {

Callers

nothing calls this directly

Calls 10

FilePathMethod · 0.80
SetOwnerMethod · 0.80
MkdirMethod · 0.80
SetFileMethod · 0.80
RmdirMethod · 0.80
LoadFunction · 0.70
NewFunction · 0.70
SetMethod · 0.65
RemoveMethod · 0.45
SaveMethod · 0.45

Tested by

no test coverage detected