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

Function pcreate

shock-client/_archive/pcreate.go:21–103  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

19}
20
21func pcreate(args []string) (err error) {
22 n := lib.Node{}
23 var filename string
24 if ne(conf.Flags["full"]) {
25 filename = (*conf.Flags["full"])
26 } else {
27 helpf("pcreate requires file path: -full=<u>")
28 }
29
30 var filesize int64
31 fh, err := os.Open(filename)
32 if err != nil {
33 handleString(fmt.Sprintf("Error open file: %s\n", err.Error()))
34 }
35 if fi, _ := fh.Stat(); err == nil {
36 filesize = fi.Size()
37 }
38
39 chunks := int(filesize / (conf.CHUNK_SIZE))
40 if filesize%conf.CHUNK_SIZE != 0 {
41 chunks += 1
42 }
43
44 if chunks == 1 {
45 opts := lib.Opts{}
46 opts["upload_type"] = "full"
47 opts["full"] = filename
48 if err := n.Create(opts); err != nil {
49 handleString(fmt.Sprintf("Error creating node: %s\n", err.Error()))
50 } else {
51 n.PP()
52 }
53 } else {
54 threads, _ := strconv.Atoi(*conf.Flags["threads"])
55 if threads == 0 {
56 threads = 1
57 }
58
59 //create node
60 opts := lib.Opts{}
61 opts["upload_type"] = "parts"
62 opts["parts"] = strconv.Itoa(chunks)
63 if err := n.Create(opts); err != nil {
64 handleString(fmt.Sprintf("Error creating node: %s\n", err.Error()))
65 }
66
67 workers := pool.New(threads)
68 workers.Run()
69 for i := 0; i < chunks; i++ {
70 size := int64(conf.CHUNK_SIZE)
71 if size*(int64(i)+1) > filesize {
72 size = filesize - size*(int64(i))
73 }
74 workers.Add(uploader, n, (i + 1), fh, size)
75 }
76 workers.Wait()
77 maxRetries := 10
78 for i := 1; i <= maxRetries; i++ {

Callers 1

mainFunction · 0.85

Calls 9

CreateMethod · 0.95
PPMethod · 0.95
GetMethod · 0.95
neFunction · 0.85
helpfFunction · 0.85
handleStringFunction · 0.85
StatMethod · 0.65
ErrorMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected