fix test lifecycle expiration

This commit is contained in:
Konstantin Lebedev
2025-11-03 17:59:44 +05:00
parent aea7327089
commit 47c7d5fc8f
3 changed files with 38 additions and 1 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ func (entry *Entry) IsDirectoryKeyObject() bool {
func (entry *Entry) IsExpired() bool {
return entry.Attributes != nil && entry.Attributes.TtlSec > 0 &&
(entry.Attributes.GetMtime()+int64(entry.Attributes.TtlSec)) >= time.Now().UTC().Unix()
(entry.Attributes.GetMtime()+int64(entry.Attributes.TtlSec)) >= time.Now().Unix()
}
func (entry *Entry) FileMode() (fileMode os.FileMode) {
+32
View File
@@ -3,6 +3,7 @@ package s3api
import (
"context"
"fmt"
"math"
"strings"
"github.com/seaweedfs/seaweedfs/weed/glog"
@@ -108,6 +109,37 @@ func (s3a *S3ApiServer) updateEntry(parentDirectoryPath string, newEntry *filer_
return err
}
func (s3a *S3ApiServer) updateEntriesTTL(parentDirectoryPath string, ttlSec int32) error {
err := s3a.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
ctx := context.Background()
err := filer_pb.SeaweedList(ctx, client, parentDirectoryPath, "", func(entry *filer_pb.Entry, isLast bool) error {
if entry.IsDirectory {
return s3a.updateEntriesTTL(fmt.Sprintf("%s/%s", parentDirectoryPath, entry.Name), ttlSec)
}
if entry.Attributes != nil {
entry.Attributes = &filer_pb.FuseAttributes{}
}
if entry.Attributes.TtlSec == ttlSec {
return nil
}
entry.Attributes.TtlSec = ttlSec
err := filer_pb.UpdateEntry(ctx, client, &filer_pb.UpdateEntryRequest{
Directory: parentDirectoryPath,
Entry: entry,
})
if err != nil {
return err
}
return nil
}, "", false, math.MaxInt32)
if err != nil {
return err
}
return nil
})
return err
}
func (s3a *S3ApiServer) getCollectionName(bucket string) string {
if s3a.option.FilerGroup != "" {
return fmt.Sprintf("%s_%s", s3a.option.FilerGroup, bucket)
+5
View File
@@ -627,6 +627,11 @@ func (s3a *S3ApiServer) PutBucketLifecycleConfigurationHandler(w http.ResponseWr
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return
}
parentDirectoryPath := fmt.Sprintf("%s/%s", s3a.option.BucketsPath, bucket)
ttlSec := int32((time.Duration(rule.Expiration.Days) * 24 * time.Hour).Seconds())
if updErr := s3a.updateEntriesTTL(parentDirectoryPath, ttlSec); updErr != nil {
glog.Errorf("PutBucketLifecycleConfigurationHandler update: %s", err)
}
changed = true
}