forked from sumatrapdfreader/sumatrapdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_upload.go
More file actions
97 lines (82 loc) · 1.93 KB
/
Copy pathfile_upload.go
File metadata and controls
97 lines (82 loc) · 1.93 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"path"
"path/filepath"
"sync"
"time"
"github.com/kjk/minioutil"
)
const filesRemoteDir = "sumatraTestFiles/"
func fileUpload(fpath string) {
ensureAllUploadCreds()
fileSize := fileSizeMust(fpath)
sha1, err := fileSha1Hex(fpath)
must(err)
dstFileName := sha1[:6] + "-" + urlify(filepath.Base(fpath))
remotePath := path.Join(filesRemoteDir, dstFileName)
sizeStr := formatSize(fileSize)
logf(ctx(), "uploading '%s' of size %s as '%s'\n", fpath, sizeStr, remotePath)
timeStart := time.Now()
upload := func(mc *minioutil.Client) {
uri := mc.URLForPath(remotePath)
if mc.Exists(remotePath) {
logf(ctx(), "Skipping upload, '%s' already exists\n", uri)
} else {
_, err := mc.UploadFile(remotePath, fpath, true)
must(err)
logf(ctx(), "Uploaded in %s\n%s\n", time.Since(timeStart), uri)
}
}
var wg sync.WaitGroup
wg.Add(1)
go func() {
upload(newMinioS3Client())
wg.Done()
}()
wg.Add(1)
go func() {
upload(newMinioBackblazeClient())
wg.Done()
}()
wg.Add(1)
go func() {
upload(newMinioSpacesClient())
wg.Done()
}()
wg.Wait()
}
func minioFilesList(mc *minioutil.Client) {
uri := mc.URLForPath("")
logf(ctx(), "filesList in '%s'\n", uri)
files := mc.ListObjects("")
for f := range files {
sizeStr := formatSize(f.Size)
logf(ctx(), "%s : %s\n", f.Key, sizeStr)
}
}
func filesList() {
ensureAllUploadCreds()
minioFilesList(newMinioBackblazeClient())
}
func deleteFilesOneOff() {
doDelete := false
prefix := "vack/"
var mc *minioutil.Client
//mc = newMinioSpacesClient()
//mc = newMinioS3Client()
//mc = newMinioBackblazeClient()
uri := mc.URLForPath("")
logf(ctx(), "deleteFiles in '%s'\n", uri)
files := mc.ListObjects(prefix)
for f := range files {
if doDelete {
err := mc.Remove(f.Key)
must(err)
uri := mc.URLForPath(f.Key)
logf(ctx(), "Deleted %s\n", uri)
} else {
sizeStr := formatSize(f.Size)
logf(ctx(), "%s : %s\n", f.Key, sizeStr)
}
}
}