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

Method Update

shock-server/node/update.go:24–496  ·  view source on GitHub ↗

Modification functions

(params map[string]string, files file.FormFiles, hasLock bool)

Source from the content-addressed store, hash-verified

22
23//Modification functions
24func (node *Node) Update(params map[string]string, files file.FormFiles, hasLock bool) (err error) {
25 // Exclusive conditions
26 // 1.1. has files[upload] (regular upload)
27 // 1.2. has files[gzip] (compressed upload)
28 // 1.3. has files[bzip2] (compressed upload)
29 // 2. has params[parts] (partial upload support)
30 // 3. has params[type] & params[source] (v_node)
31 // 4. has params[path] (set from local path)
32 // 5. has params[copy_data] (create node by copying data from another node)
33 // 6. has params[parent_node] (create node by specifying subset of records in a parent node)
34 //
35 // All condition allow setting of attributes
36 //
37 // state is saved to mongodb at end of update function
38
39 // global lock on a node if not already set
40 if !hasLock {
41 err = locker.NodeLockMgr.LockNode(node.Id)
42 if err != nil {
43 err = fmt.Errorf("(LockMgr.LockNode) %s", err.Error())
44 return
45 }
46 defer locker.NodeLockMgr.UnlockNode(node.Id)
47 }
48
49 for _, u := range util.ValidUpload {
50 if _, uploadMisplaced := params[u]; uploadMisplaced {
51 err = fmt.Errorf("form field '%s' must be file encoded", u)
52 return
53 }
54 }
55
56 isRegularUpload := false
57 uploadFile := ""
58 uploadCount := 0
59 for _, u := range util.ValidUpload {
60 if _, hasRegularUpload := files[u]; hasRegularUpload {
61 isRegularUpload = true
62 uploadFile = u
63 uploadCount += 1
64 }
65 }
66 if uploadCount > 1 {
67 err = fmt.Errorf("only one upload file allowed")
68 return
69 }
70
71 isUrlUpload := false
72 if _, hasUrlUpload := files["upload_url"]; hasUrlUpload {
73 isUrlUpload = true
74 }
75
76 _, isPartialUpload := params["parts"]
77 hasPartsFile := false
78 for key, _ := range files {
79 if _, errf := strconv.Atoi(key); errf == nil {
80 hasPartsFile = true
81 }

Callers 2

ReplaceMethod · 0.45
CreateNodeUploadFunction · 0.45

Calls 15

HasFileMethod · 0.95
HasFileLockMethod · 0.95
SetFileMethod · 0.95
closePartsMethod · 0.95
initPartsMethod · 0.95
addVirtualPartsMethod · 0.95
SetFileFromPathMethod · 0.95
PathMethod · 0.95
IndexPathMethod · 0.95
SetIndexInfoMethod · 0.95
SetFileFromSubsetMethod · 0.95
SetAttributesMethod · 0.95

Tested by

no test coverage detected