|
@ -1,18 +1,21 @@ |
|
|
package filer2 |
|
|
package filer2 |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"bytes" |
|
|
|
|
|
"fmt" |
|
|
"os" |
|
|
"os" |
|
|
"time" |
|
|
"time" |
|
|
|
|
|
|
|
|
"fmt" |
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" |
|
|
|
|
|
"github.com/golang/protobuf/proto" |
|
|
"github.com/golang/protobuf/proto" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func (entry *Entry) EncodeAttributesAndChunks() ([]byte, error) { |
|
|
func (entry *Entry) EncodeAttributesAndChunks() ([]byte, error) { |
|
|
message := &filer_pb.Entry{ |
|
|
message := &filer_pb.Entry{ |
|
|
Attributes: EntryAttributeToPb(entry), |
|
|
Attributes: EntryAttributeToPb(entry), |
|
|
Chunks: entry.Chunks, |
|
|
Chunks: entry.Chunks, |
|
|
|
|
|
Extended: entry.Extended, |
|
|
} |
|
|
} |
|
|
return proto.Marshal(message) |
|
|
return proto.Marshal(message) |
|
|
} |
|
|
} |
|
@ -27,6 +30,8 @@ func (entry *Entry) DecodeAttributesAndChunks(blob []byte) error { |
|
|
|
|
|
|
|
|
entry.Attr = PbToEntryAttribute(message.Attributes) |
|
|
entry.Attr = PbToEntryAttribute(message.Attributes) |
|
|
|
|
|
|
|
|
|
|
|
entry.Extended = message.Extended |
|
|
|
|
|
|
|
|
entry.Chunks = message.Chunks |
|
|
entry.Chunks = message.Chunks |
|
|
|
|
|
|
|
|
return nil |
|
|
return nil |
|
@ -84,6 +89,10 @@ func EqualEntry(a, b *Entry) bool { |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !eq(a.Extended, b.Extended) { |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
for i := 0; i < len(a.Chunks); i++ { |
|
|
for i := 0; i < len(a.Chunks); i++ { |
|
|
if !proto.Equal(a.Chunks[i], b.Chunks[i]) { |
|
|
if !proto.Equal(a.Chunks[i], b.Chunks[i]) { |
|
|
return false |
|
|
return false |
|
@ -91,3 +100,17 @@ func EqualEntry(a, b *Entry) bool { |
|
|
} |
|
|
} |
|
|
return true |
|
|
return true |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func eq(a, b map[string][]byte) bool { |
|
|
|
|
|
if len(a) != len(b) { |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for k, v := range a { |
|
|
|
|
|
if w, ok := b[k]; !ok || bytes.Equal(v, w) { |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true |
|
|
|
|
|
} |