diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-08-15 09:32:47 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-08-15 09:32:47 -0700 |
| commit | c647deace16ec1a3f0c11d92dc5fa15ec30012e4 (patch) | |
| tree | 7b13546507283b5566a069d03dc3371ccd2d7290 /weed/filer2 | |
| parent | c03bb180eb5fc96e79324f0aa5ec7cd9b674f901 (diff) | |
| download | seaweedfs-c647deace16ec1a3f0c11d92dc5fa15ec30012e4.tar.xz seaweedfs-c647deace16ec1a3f0c11d92dc5fa15ec30012e4.zip | |
file size support set file length
use Attr.FileSize and TotalChunkSize to determine file size
Diffstat (limited to 'weed/filer2')
| -rw-r--r-- | weed/filer2/entry.go | 10 | ||||
| -rw-r--r-- | weed/filer2/entry_codec.go | 2 | ||||
| -rw-r--r-- | weed/filer2/filechunks.go | 4 |
3 files changed, 15 insertions, 1 deletions
diff --git a/weed/filer2/entry.go b/weed/filer2/entry.go index 00b9b132d..fedfde40d 100644 --- a/weed/filer2/entry.go +++ b/weed/filer2/entry.go @@ -22,6 +22,7 @@ type Attr struct { GroupNames []string SymlinkTarget string Md5 []byte + FileSize uint64 } func (attr Attr) IsDirectory() bool { @@ -39,7 +40,7 @@ type Entry struct { } func (entry *Entry) Size() uint64 { - return TotalSize(entry.Chunks) + return maxUint64(TotalSize(entry.Chunks), entry.FileSize) } func (entry *Entry) Timestamp() time.Time { @@ -81,3 +82,10 @@ func FromPbEntry(dir string, entry *filer_pb.Entry) *Entry { Chunks: entry.Chunks, } } + +func maxUint64(x, y uint64) uint64 { + if x > y { + return x + } + return y +} diff --git a/weed/filer2/entry_codec.go b/weed/filer2/entry_codec.go index 47c911011..4d615194f 100644 --- a/weed/filer2/entry_codec.go +++ b/weed/filer2/entry_codec.go @@ -53,6 +53,7 @@ func EntryAttributeToPb(entry *Entry) *filer_pb.FuseAttributes { GroupName: entry.Attr.GroupNames, SymlinkTarget: entry.Attr.SymlinkTarget, Md5: entry.Attr.Md5, + FileSize: entry.Attr.FileSize, } } @@ -73,6 +74,7 @@ func PbToEntryAttribute(attr *filer_pb.FuseAttributes) Attr { t.GroupNames = attr.GroupName t.SymlinkTarget = attr.SymlinkTarget t.Md5 = attr.Md5 + t.FileSize = attr.FileSize return t } diff --git a/weed/filer2/filechunks.go b/weed/filer2/filechunks.go index ea7772b4a..9de888d50 100644 --- a/weed/filer2/filechunks.go +++ b/weed/filer2/filechunks.go @@ -20,6 +20,10 @@ func TotalSize(chunks []*filer_pb.FileChunk) (size uint64) { return } +func FileSize(entry *filer_pb.Entry) (size uint64) { + return maxUint64(TotalSize(entry.Chunks), entry.Attributes.FileSize) +} + func ETag(entry *filer_pb.Entry) (etag string) { if entry.Attributes == nil || entry.Attributes.Md5 == nil { return ETagChunks(entry.Chunks) |
