Skip to content

Commit 8493102

Browse files
author
JojiiOfficial
committed
remove server dependency
delete local file on download cancel
1 parent 806e512 commit 8493102

File tree

6 files changed

+36
-34
lines changed

6 files changed

+36
-34
lines changed

cData.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"os"
88

99
"github.com/DataManager-Go/DataManagerCLI/commands"
10-
"github.com/DataManager-Go/DataManagerServer/constants"
1110
libdm "github.com/DataManager-Go/libdatamanager"
1211
)
1312

@@ -58,7 +57,7 @@ func initInputKey(cData commands.CommandData) *commands.CommandData {
5857
if randKeySize > 0 && cData.RequestedEncryptionInput() {
5958
// Check correct keylen for given encryption
6059
switch *appFileEncryption {
61-
case constants.EncryptionCiphers[0]:
60+
case libdm.EncryptionCiphers[0]:
6261
// AES
6362
if !vaildAESkeylen(randKeySize) {
6463
fmt.Printf("The keysize %d is invalid\n", randKeySize)

commands/FileDownload.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,26 @@ func (cData *CommandData) DownloadFile(data *DownloadData) {
133133
return
134134
}
135135

136-
err = writeFile(cData, resp, outFile)
137-
if err != nil {
138-
// Delete file on error. On checksum error only delete if --verify was passed
139-
if err != libdm.ErrChecksumNotMatch || cData.VerifyFile {
140-
ShredderFile(outFile, -1)
141-
}
136+
c := make(chan string, 1)
142137

143-
return
144-
}
138+
go func() {
139+
err = writeFile(cData, resp, outFile)
140+
if err != nil {
141+
// Delete file on error. On checksum error only delete if --verify was passed
142+
if err != libdm.ErrChecksumNotMatch || cData.VerifyFile {
143+
ShredderFile(outFile, -1)
144+
}
145145

146-
printSuccess("saved '%s'", outFile)
146+
return
147+
}
148+
c <- ""
149+
}()
150+
151+
awaitOrInterrupt(c, func(s os.Signal) {
152+
ShredderFile(outFile, -1)
153+
}, func(s string) {
154+
printSuccess("saved '%s'", outFile)
155+
})
147156
}
148157

149158
func writeFile(cData *CommandData, resp *libdm.FileDownloadResponse, file string) error {

commands/Namespace.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ package commands
33
import (
44
"fmt"
55

6-
"github.com/DataManager-Go/DataManagerServer/constants"
6+
"github.com/fatih/color"
7+
)
8+
9+
//Colorized strings
10+
var (
11+
GreenSuccessfully = color.HiGreenString("Successfully")
12+
RedError = color.HiRedString("Error")
713
)
814

915
// CreateNamespace creates a namespace
@@ -14,7 +20,7 @@ func CreateNamespace(cData *CommandData, name string, customNS bool) {
1420
return
1521
}
1622

17-
fmt.Printf("%s created namespace '%s'\n", constants.GreenSuccessfully, createResponse.String)
23+
fmt.Printf("%s created namespace '%s'\n", GreenSuccessfully, createResponse.String)
1824
}
1925

2026
// UpdateNamespace update a namespace
@@ -25,7 +31,7 @@ func UpdateNamespace(cData *CommandData, name, newName string, customNS bool) {
2531
return
2632
}
2733

28-
fmt.Printf("%s updated namespace '%s'\n", constants.GreenSuccessfully, updateResponse.String)
34+
fmt.Printf("%s updated namespace '%s'\n", GreenSuccessfully, updateResponse.String)
2935
}
3036

3137
// DeleteNamespace update a namespace
@@ -36,7 +42,7 @@ func DeleteNamespace(cData *CommandData, name string) {
3642
return
3743
}
3844

39-
fmt.Printf("%s deleted namespace '%s'\n", constants.GreenSuccessfully, deleteResponse.String)
45+
fmt.Printf("%s deleted namespace '%s'\n", GreenSuccessfully, deleteResponse.String)
4046
}
4147

4248
// ListNamespace lists your namespace

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ replace github.com/gosuri/uiprogress v0.0.1 => github.com/JojiiOfficial/uiprogre
66

77
require (
88
github.com/CovenantSQL/go-sqlite3-encrypt v1.9.0
9-
github.com/DataManager-Go/DataManagerServer v1.0.0
109
github.com/DataManager-Go/libdatamanager v1.1.14
11-
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200411170352-eece8060bcb8
10+
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200412231115-a82508b229bb
1211
github.com/JojiiOfficial/configService v0.0.0-20200219132202-6e71512e2e28
1312
github.com/JojiiOfficial/gaw v1.2.1
1413
github.com/JojiiOfficial/shred v1.2.1
14+
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
15+
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
1516
github.com/atotto/clipboard v0.1.2
1617
github.com/dustin/go-humanize v1.0.0
1718
github.com/fatih/color v1.9.0

go.sum

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
33
github.com/CovenantSQL/go-sqlite3-encrypt v1.9.0 h1:GPtIZW4KZhul21SrmmpgUCx+wEPhnFlzOceTtzMypzs=
44
github.com/CovenantSQL/go-sqlite3-encrypt v1.9.0/go.mod h1:EH9sjhhyDGHNIj/Wx59f7CURbVp1C1x/eRVi07WPsvg=
5-
github.com/DataManager-Go/DataManagerServer v1.0.0 h1:KcxPwDA3B4cNdjKYQc4/GYOq62eKNOI+IqhFHPVijIQ=
6-
github.com/DataManager-Go/DataManagerServer v1.0.0/go.mod h1:oJCEcZUpFwrLfXQAcYnDkNrh1la4gw3931RnComDsn8=
75
github.com/DataManager-Go/libdatamanager v1.0.10/go.mod h1:iLQrv9tvUkcx9nA+x51eUR9juV0JgIOnFrhPISxWWUE=
86
github.com/DataManager-Go/libdatamanager v1.1.14 h1:Mric8SgGRISSp6N+Gl7AvpzLEfSeaAVyL+YnAqOr4d0=
97
github.com/DataManager-Go/libdatamanager v1.1.14/go.mod h1:s2ywdIZpWEfgxJ7iMtCOdLCNaHVnO8dr7e9cE2NzgL4=
108
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200411170352-eece8060bcb8 h1:MU5d6F7BfvFCRjYuDCfehpamDo5Qm/Pnkmnpqqb+obw=
119
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200411170352-eece8060bcb8/go.mod h1:RfoOPe8dQgubuBUmtqEYu1Ny0fT+htZH/ArrEl0dcHQ=
10+
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200412231115-a82508b229bb h1:w53VeyM2XITRcIAGf8ArdKy1Q60McFIbuL+Jz4o6HV4=
11+
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200412231115-a82508b229bb/go.mod h1:RfoOPe8dQgubuBUmtqEYu1Ny0fT+htZH/ArrEl0dcHQ=
1212
github.com/JojiiOfficial/configService v0.0.0-20200219132202-6e71512e2e28 h1:nYoIExG+Z/gSLS9Jbpu6lnrh+m6e9gTxQfGhanTsExE=
1313
github.com/JojiiOfficial/configService v0.0.0-20200219132202-6e71512e2e28/go.mod h1:j1kHFoYWAbLRPE5nyAAtODwUc0xwd2+ifPZ3uCAgv/g=
1414
github.com/JojiiOfficial/gaw v1.2.0 h1:qIu6xVtCvd4yhAfI0MGGr5CPus0hpY+eFUDUGqc/sYQ=
1515
github.com/JojiiOfficial/gaw v1.2.0/go.mod h1:Y0hrpN0iX0L5bBf/8+kIER7R/m4GTNuKkifXisMG4S4=
1616
github.com/JojiiOfficial/gaw v1.2.1 h1:zwVLf5TQrXQF+pwI+/sVsfxTxmAZbZ5BjVT/nKxb2Ck=
1717
github.com/JojiiOfficial/gaw v1.2.1/go.mod h1:Y0hrpN0iX0L5bBf/8+kIER7R/m4GTNuKkifXisMG4S4=
18-
github.com/JojiiOfficial/shred v1.0.1 h1:5WIaDlDzcIuYIj7wk+P2H05+LHxcdctCL5LUnS51frk=
19-
github.com/JojiiOfficial/shred v1.0.1/go.mod h1:5bGv1PyUFAzdVb/+dvQYrfrIvJFcUsO7hJ1yoBR5A+o=
2018
github.com/JojiiOfficial/shred v1.2.1 h1:658CFVTqcAkYVg815vW+guYnyJTLOIoS15tMyPTYhNo=
2119
github.com/JojiiOfficial/shred v1.2.1/go.mod h1:/OAxd6eYOhrXb3KW+2wmDog2BiFlUld8oJEKa+xblxU=
2220
github.com/JojiiOfficial/uiprogress v1.0.3 h1:FeSJKEPlfyUokrA4zi/hl6s3m2DAHdo8TXDiJ44aotU=
@@ -29,9 +27,8 @@ github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzb
2927
github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
3028
github.com/danieljoos/wincred v1.0.2 h1:zf4bhty2iLuwgjgpraD2E9UbvO+fe54XXGJbOwe23fU=
3129
github.com/danieljoos/wincred v1.0.2/go.mod h1:SnuYRW9lp1oJrZX/dXJqr0cPK5gYXqx3EJbmjhLdK9U=
30+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
3231
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
34-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3532
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
3633
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
3734
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM=
@@ -42,26 +39,21 @@ github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DP
4239
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
4340
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
4441
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
45-
github.com/gabriel-vasile/mimetype v1.0.5/go.mod h1:6CDPel/o/3/s4+bp6kIbsWATq8pmgOisOPG40CJa6To=
4642
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
4743
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
4844
github.com/godbus/dbus v4.1.0+incompatible h1:WqqLRTsQic3apZUK9qC5sGNfXthmPXzUZ7nQPrNITa4=
4945
github.com/godbus/dbus v4.1.0+incompatible/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
5046
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
5147
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
5248
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
53-
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
5449
github.com/gosuri/uilive v0.0.4 h1:hUEBpQDj8D8jXgtCdBu7sWsy5sbW/5GhuO8KBwJ2jyY=
5550
github.com/gosuri/uilive v0.0.4/go.mod h1:V/epo5LjjlDE5RJUcqx8dbw+zc93y5Ya3yg8tfZ74VI=
56-
github.com/h2non/filetype v1.0.12/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
5751
github.com/jinzhu/gorm v1.9.12 h1:Drgk1clyWT9t9ERbzHza6Mj/8FY/CqMyVzOiHviMo6Q=
5852
github.com/jinzhu/gorm v1.9.12/go.mod h1:vhTjlKSJUTWNtcbQtrMBFCxy7eXTzeCAzfL5fBZT/Qs=
5953
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
6054
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
6155
github.com/jinzhu/now v1.0.1 h1:HjfetcXq097iXP0uoPCdnM4Efp5/9MsM0/M+XOTeR3M=
6256
github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
63-
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
64-
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
6557
github.com/kyokomi/emoji v2.2.1+incompatible h1:uP/6J5y5U0XxPh6fv8YximpVD1uMrshXG78I1+uF5SA=
6658
github.com/kyokomi/emoji v2.2.1+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2pxoszVseX1DNoGtU2tBA=
6759
github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4=
@@ -83,11 +75,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
8375
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8476
github.com/sbani/go-humanizer v0.3.1 h1:tknML0P8VM52Ve22s7yDmwR5+O/iYlcsB4LH+1wbbqo=
8577
github.com/sbani/go-humanizer v0.3.1/go.mod h1:e9VBnVLK9RD0xgcSvZDuL9gX9mSaCTr4xE+VSBuG2KM=
86-
github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q=
87-
github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo=
8878
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
8979
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
90-
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
9180
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
9281
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
9382
github.com/zalando/go-keyring v0.0.0-20200121091418-667557018717 h1:3M/uUZajYn/082wzUajekePxpUAZhMTfXvI9R+26SJ0=
@@ -102,7 +91,6 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
10291
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
10392
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
10493
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
105-
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
10694
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
10795
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
10896
golang.org/x/sys v0.0.0-20200406155108-e3b113bbe6a4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"log"
77
"os"
88

9-
"github.com/DataManager-Go/DataManagerServer/constants"
109
libdm "github.com/DataManager-Go/libdatamanager"
1110
dmConfig "github.com/DataManager-Go/libdatamanager/config"
1211
"github.com/JojiiOfficial/gaw"
@@ -55,7 +54,7 @@ var (
5554
appVerify = app.Flag("verify", "Verify a file using a checksum to prevent errors").Bool()
5655
appNoDecrypt = app.Flag("no-decrypt", "Don't decrypt files").Bool()
5756
appForce = app.Flag("force", "Forces an action").Short('f').Bool()
58-
appFileEncryption = app.Flag("encryption", "Encrypt/Decrypt the file").Short('e').HintOptions(constants.EncryptionCiphers...).String()
57+
appFileEncryption = app.Flag("encryption", "Encrypt/Decrypt the file").Short('e').HintOptions(libdm.EncryptionCiphers...).String()
5958

6059
// Output related flags
6160
appDetails = app.Flag("details", "Print more details of something").Short('d').Counter()

0 commit comments

Comments
 (0)