aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chrislusf@users.noreply.github.com>2022-04-12 02:03:31 -0700
committerGitHub <noreply@github.com>2022-04-12 02:03:31 -0700
commitdd13764a5c12cd63e79cd733f973de9f758029e1 (patch)
tree8f994b871a352ec01db5166ff1b941a07936a3a3
parent72db181d685afc5f60bd34bbd2733d22d1a65ddc (diff)
parent76b1c5ce67bb1b680b2257bcb2996bed06691be8 (diff)
downloadseaweedfs-dd13764a5c12cd63e79cd733f973de9f758029e1.tar.xz
seaweedfs-dd13764a5c12cd63e79cd733f973de9f758029e1.zip
Merge pull request #2900 from kmlebedev/fix_cleanupUploads
avoid breaking loop in cleanupUploads if error is empty
-rw-r--r--weed/shell/command_s3_clean_uploads.go18
1 files changed, 14 insertions, 4 deletions
diff --git a/weed/shell/command_s3_clean_uploads.go b/weed/shell/command_s3_clean_uploads.go
index 4f893df7a..a6dc8f574 100644
--- a/weed/shell/command_s3_clean_uploads.go
+++ b/weed/shell/command_s3_clean_uploads.go
@@ -3,6 +3,7 @@ package shell
import (
"flag"
"fmt"
+ "github.com/chrislusf/seaweedfs/weed/security"
"github.com/chrislusf/seaweedfs/weed/util"
"io"
"math"
@@ -39,6 +40,8 @@ func (c *commandS3CleanUploads) Do(args []string, commandEnv *CommandEnv, writer
return nil
}
+ signingKey := util.GetViper().GetString("jwt.signing.key")
+
var filerBucketsPath string
filerBucketsPath, err = readFilerBucketsPath(commandEnv)
if err != nil {
@@ -55,14 +58,16 @@ func (c *commandS3CleanUploads) Do(args []string, commandEnv *CommandEnv, writer
}
for _, bucket := range buckets {
- c.cleanupUploads(commandEnv, writer, filerBucketsPath, bucket, *uploadedTimeAgo)
+ if err := c.cleanupUploads(commandEnv, writer, filerBucketsPath, bucket, *uploadedTimeAgo, signingKey); err != nil {
+ fmt.Fprintf(writer, fmt.Sprintf("failed cleanup uploads for backet %s: %v", bucket, err))
+ }
}
return err
}
-func (c *commandS3CleanUploads) cleanupUploads(commandEnv *CommandEnv, writer io.Writer, filerBucketsPath string, bucket string, timeAgo time.Duration) error {
+func (c *commandS3CleanUploads) cleanupUploads(commandEnv *CommandEnv, writer io.Writer, filerBucketsPath string, bucket string, timeAgo time.Duration, signingKey string) error {
uploadsDir := filerBucketsPath + "/" + bucket + "/.uploads"
var staleUploads []string
now := time.Now()
@@ -77,12 +82,17 @@ func (c *commandS3CleanUploads) cleanupUploads(commandEnv *CommandEnv, writer io
return fmt.Errorf("list uploads under %v: %v", uploadsDir, err)
}
+ var encodedJwt security.EncodedJwt
+ if signingKey != "" {
+ encodedJwt = security.GenJwtForFilerServer(security.SigningKey(signingKey), 15*60)
+ }
+
for _, staleUpload := range staleUploads {
deleteUrl := fmt.Sprintf("http://%s%s/%s?recursive=true&ignoreRecursiveError=true", commandEnv.option.FilerAddress.ToHttpAddress(), uploadsDir, staleUpload)
fmt.Fprintf(writer, "purge %s\n", deleteUrl)
- err = util.Delete(deleteUrl, "")
- if err != nil {
+ err = util.Delete(deleteUrl, string(encodedJwt))
+ if err != nil && err.Error() != "" {
return fmt.Errorf("purge %s/%s: %v", uploadsDir, staleUpload, err)
}
}