aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2021-02-22 12:22:49 -0800
committerChris Lu <chris.lu@gmail.com>2021-02-22 12:22:49 -0800
commit44bdfb2d157684e0862408a3a5146179d62839db (patch)
tree55a3deed6a77cbcb1416199d0c7c42578d0be955
parent62191b08eafe896f0f403bbf759f1cb07a59856f (diff)
downloadseaweedfs-44bdfb2d157684e0862408a3a5146179d62839db.tar.xz
seaweedfs-44bdfb2d157684e0862408a3a5146179d62839db.zip
filer: avoid encryption and compression at the same time
fix https://github.com/chrislusf/seaweedfs/issues/1828
-rw-r--r--weed/operation/upload_content.go33
1 files changed, 17 insertions, 16 deletions
diff --git a/weed/operation/upload_content.go b/weed/operation/upload_content.go
index 934075ff3..70428bb07 100644
--- a/weed/operation/upload_content.go
+++ b/weed/operation/upload_content.go
@@ -130,7 +130,8 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i
// gzip if possible
// this could be double copying
clearDataLen = len(data)
- if shouldGzipNow {
+ clearData := data
+ if shouldGzipNow && !cipher {
compressed, compressErr := util.GzipData(data)
// fmt.Printf("data is compressed from %d ==> %d\n", len(data), len(compressed))
if compressErr == nil {
@@ -139,7 +140,7 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i
}
} else if isInputCompressed {
// just to get the clear data length
- clearData, err := util.DecompressData(data)
+ clearData, err = util.DecompressData(data)
if err == nil {
clearDataLen = len(clearData)
}
@@ -150,7 +151,7 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i
// encrypt
cipherKey := util.GenCipherKey()
- encryptedData, encryptionErr := util.Encrypt(data, cipherKey)
+ encryptedData, encryptionErr := util.Encrypt(clearData, cipherKey)
if encryptionErr != nil {
err = fmt.Errorf("encrypt input: %v", encryptionErr)
return
@@ -161,26 +162,26 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i
_, err = w.Write(encryptedData)
return
}, "", false, len(encryptedData), "", nil, jwt)
- if uploadResult != nil {
- uploadResult.Name = filename
- uploadResult.Mime = mtype
- uploadResult.CipherKey = cipherKey
+ if uploadResult == nil {
+ return
}
+ uploadResult.Name = filename
+ uploadResult.Mime = mtype
+ uploadResult.CipherKey = cipherKey
+ uploadResult.Size = uint32(clearDataLen)
} else {
// upload data
uploadResult, err = upload_content(uploadUrl, func(w io.Writer) (err error) {
_, err = w.Write(data)
return
}, filename, contentIsGzipped, len(data), mtype, pairMap, jwt)
- }
-
- if uploadResult == nil {
- return
- }
-
- uploadResult.Size = uint32(clearDataLen)
- if contentIsGzipped {
- uploadResult.Gzip = 1
+ if uploadResult == nil {
+ return
+ }
+ uploadResult.Size = uint32(clearDataLen)
+ if contentIsGzipped {
+ uploadResult.Gzip = 1
+ }
}
return uploadResult, err