Skip to content

Commit 8a03490

Browse files
author
JojiiOfficial
committed
fix shredder file on download
1 parent 8493102 commit 8a03490

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

commands/File.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func (cData *CommandData) EditFile(id uint) {
286286
}
287287

288288
// Save File
289-
err = resp.WriteToFile(filePath, 0600)
289+
err = resp.WriteToFile(filePath, 0600, nil)
290290
if err != nil {
291291
printError("downloading file", err.Error())
292292
return
@@ -324,7 +324,6 @@ func (cData *CommandData) EditFile(id uint) {
324324
cData.Encryption = resp.Encryption
325325

326326
// Replace file on server with new file
327-
// cData.UploadFile([]string{filePath}, serverName, "", false, false, false, id, 1, false)
328327
cData.UploadFile([]string{filePath}, 1, &UploadData{
329328
ReplaceFile: resp.FileID,
330329
Progress: uiprogress.New(),

commands/FileDownload.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ func (cData *CommandData) ViewFile(data *DownloadData) {
7878
defer ShredderFile(tmpFile, -1)
7979

8080
// Write file
81-
if err = writeFile(cData, resp, tmpFile); err != nil {
81+
if err = writeFile(cData, resp, tmpFile, nil); err != nil {
8282
return
8383
}
8484

8585
// Preview tempfile
8686
previewFile(tmpFile)
8787
} else {
8888
// Display file in os.Stdout (cli)
89-
err = resp.SaveTo(os.Stdout)
89+
err = resp.SaveTo(os.Stdout, nil)
9090
if err != nil {
9191
printResponseError(err, "downloading file")
9292
return
@@ -133,35 +133,42 @@ func (cData *CommandData) DownloadFile(data *DownloadData) {
133133
return
134134
}
135135

136+
cancel := make(chan bool, 1)
136137
c := make(chan string, 1)
137138

138139
go func() {
139-
err = writeFile(cData, resp, outFile)
140+
err = writeFile(cData, resp, outFile, cancel)
140141
if err != nil {
141142
// Delete file on error. On checksum error only delete if --verify was passed
142143
if err != libdm.ErrChecksumNotMatch || cData.VerifyFile {
143144
ShredderFile(outFile, -1)
144145
}
145146

147+
c <- "exit"
146148
return
147149
}
150+
148151
c <- ""
149152
}()
150153

154+
// Wait for download to be done or delete file on interrupt
151155
awaitOrInterrupt(c, func(s os.Signal) {
152-
ShredderFile(outFile, -1)
156+
cancel <- true
157+
158+
// await shredder
159+
<-c
153160
}, func(s string) {
154161
printSuccess("saved '%s'", outFile)
155162
})
156163
}
157164

158-
func writeFile(cData *CommandData, resp *libdm.FileDownloadResponse, file string) error {
165+
func writeFile(cData *CommandData, resp *libdm.FileDownloadResponse, file string, cancel chan bool) error {
159166
// Save file to tempFile
160-
err := resp.WriteToFile(file, 0600)
167+
err := resp.WriteToFile(file, 0600, cancel)
161168
if err != nil {
162169
if err == libdm.ErrChecksumNotMatch {
163170
cData.printChecksumError(resp)
164-
} else {
171+
} else if err != libdm.ErrCancelled {
165172
printError("downloading file", err.Error())
166173
}
167174
}

commands/FileUpload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (cData *CommandData) uploadFile(uploadRequest *libdm.UploadRequest, uploadD
138138
// Start uploading
139139
go func() {
140140
c := make(chan string, 1)
141-
uploadResponse, err = uploadRequest.UploadFromReader(r, size, c)
141+
uploadResponse, err = uploadRequest.UploadFromReader(r, size, c, nil)
142142
done <- <-c
143143
}()
144144

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ 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/libdatamanager v1.1.14
9+
github.com/DataManager-Go/libdatamanager v1.1.15
1010
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200412231115-a82508b229bb
1111
github.com/JojiiOfficial/configService v0.0.0-20200219132202-6e71512e2e28
1212
github.com/JojiiOfficial/gaw v1.2.1

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
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=
55
github.com/DataManager-Go/libdatamanager v1.0.10/go.mod h1:iLQrv9tvUkcx9nA+x51eUR9juV0JgIOnFrhPISxWWUE=
6-
github.com/DataManager-Go/libdatamanager v1.1.14 h1:Mric8SgGRISSp6N+Gl7AvpzLEfSeaAVyL+YnAqOr4d0=
7-
github.com/DataManager-Go/libdatamanager v1.1.14/go.mod h1:s2ywdIZpWEfgxJ7iMtCOdLCNaHVnO8dr7e9cE2NzgL4=
8-
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200411170352-eece8060bcb8 h1:MU5d6F7BfvFCRjYuDCfehpamDo5Qm/Pnkmnpqqb+obw=
9-
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200411170352-eece8060bcb8/go.mod h1:RfoOPe8dQgubuBUmtqEYu1Ny0fT+htZH/ArrEl0dcHQ=
6+
github.com/DataManager-Go/libdatamanager v1.1.15 h1:6ftBaMXLWD1hlxjylidh578W4afVH8Yb00Va8HYXBeg=
7+
github.com/DataManager-Go/libdatamanager v1.1.15/go.mod h1:s2ywdIZpWEfgxJ7iMtCOdLCNaHVnO8dr7e9cE2NzgL4=
108
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200412231115-a82508b229bb h1:w53VeyM2XITRcIAGf8ArdKy1Q60McFIbuL+Jz4o6HV4=
119
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200412231115-a82508b229bb/go.mod h1:RfoOPe8dQgubuBUmtqEYu1Ny0fT+htZH/ArrEl0dcHQ=
1210
github.com/JojiiOfficial/configService v0.0.0-20200219132202-6e71512e2e28 h1:nYoIExG+Z/gSLS9Jbpu6lnrh+m6e9gTxQfGhanTsExE=

0 commit comments

Comments
 (0)