aboutsummaryrefslogtreecommitdiff
path: root/weed/pb/filer_pb/filer_pb_helper.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/pb/filer_pb/filer_pb_helper.go')
-rw-r--r--weed/pb/filer_pb/filer_pb_helper.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/weed/pb/filer_pb/filer_pb_helper.go b/weed/pb/filer_pb/filer_pb_helper.go
index b5fd4e1e0..c8dd19d59 100644
--- a/weed/pb/filer_pb/filer_pb_helper.go
+++ b/weed/pb/filer_pb/filer_pb_helper.go
@@ -9,6 +9,7 @@ import (
"time"
"github.com/seaweedfs/seaweedfs/weed/glog"
+ "github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
"github.com/viant/ptrie"
"google.golang.org/protobuf/proto"
@@ -24,6 +25,31 @@ func (entry *Entry) IsDirectoryKeyObject() bool {
return entry.IsDirectory && entry.Attributes != nil && entry.Attributes.Mime != ""
}
+func (entry *Entry) GetExpiryTime() (expiryTime int64) {
+ // For S3 objects with lifecycle expiration, use Mtime (modification time)
+ // For regular TTL entries, use Crtime (creation time) for backward compatibility
+ if entry.Extended != nil {
+ if _, hasS3Expiry := entry.Extended[s3_constants.SeaweedFSExpiresS3]; hasS3Expiry {
+ // S3 lifecycle expiration: base TTL on modification time
+ expiryTime = entry.Attributes.Mtime
+ if expiryTime == 0 {
+ expiryTime = entry.Attributes.Crtime
+ }
+ expiryTime += int64(entry.Attributes.TtlSec)
+ return expiryTime
+ }
+ }
+
+ // Regular TTL expiration: base on creation time only
+ expiryTime = entry.Attributes.Crtime + int64(entry.Attributes.TtlSec)
+ return expiryTime
+}
+
+func (entry *Entry) IsExpired() bool {
+ return entry != nil && entry.Attributes != nil && entry.Attributes.TtlSec > 0 &&
+ time.Now().Unix() >= entry.GetExpiryTime()
+}
+
func (entry *Entry) FileMode() (fileMode os.FileMode) {
if entry != nil && entry.Attributes != nil {
fileMode = os.FileMode(entry.Attributes.FileMode)