mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 21:30:16 +02:00
fix zipping
This commit is contained in:
parent
adff8400be
commit
0d5836b4e8
3 changed files with 7 additions and 16 deletions
10
src/files.go
10
src/files.go
|
@ -97,15 +97,7 @@ func (c *Croc) getFilesReady() (err error) {
|
|||
return
|
||||
}
|
||||
// encrypt file data
|
||||
// create temporary filename
|
||||
var f *os.File
|
||||
f, err = ioutil.TempFile(".", "croc-encrypted")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.crocFileEncrypted = f.Name()
|
||||
f.Close()
|
||||
os.Remove(c.crocFileEncrypted)
|
||||
c.crocFileEncrypted = tempFileName("croc-encrypted")
|
||||
err = encryptFile(c.crocFile, c.crocFileEncrypted, passphrase)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
@ -78,10 +78,7 @@ func zipFile(fname string, compress bool) (writtenFilename string, err error) {
|
|||
log.Error(err)
|
||||
return
|
||||
}
|
||||
defer os.Chdir(curdir)
|
||||
os.Chdir(pathtofile)
|
||||
|
||||
newfile, err := ioutil.TempFile(".", "croc-unencrypted")
|
||||
newfile, err := ioutil.TempFile(".", "croc-zipped")
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
|
@ -89,6 +86,9 @@ func zipFile(fname string, compress bool) (writtenFilename string, err error) {
|
|||
writtenFilename = newfile.Name()
|
||||
defer newfile.Close()
|
||||
|
||||
defer os.Chdir(curdir)
|
||||
os.Chdir(pathtofile)
|
||||
|
||||
zipWriter := zip.NewWriter(newfile)
|
||||
zipWriter.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) {
|
||||
if compress {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package croc
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
log "github.com/cihub/seelog"
|
||||
|
@ -12,10 +11,10 @@ func TestZip(t *testing.T) {
|
|||
defer log.Flush()
|
||||
writtenFilename, err := zipFile("../testing_data", false)
|
||||
assert.Nil(t, err)
|
||||
defer os.Remove(writtenFilename)
|
||||
// defer os.Remove(writtenFilename)
|
||||
|
||||
err = unzipFile(writtenFilename, ".")
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, exists("testing_data"))
|
||||
os.RemoveAll("testing_data")
|
||||
// os.RemoveAll("testing_data")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue