mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
filer: compare IF_ENTRY_EQUAL in canonical form on both sides
The clause serialized the expected entry through the codec round-trip but compared it to the raw serialized form of the stored entry, so any field the codec derives on decode broke equality — an unset atime reads back as mtime, and a stored entry that never recorded one never matched. Run the same normalization over the stored entry's serialized form. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
959d4fd3ff
commit
e04a9ff8a0
1 file changed
+12
-8
@@ -87,14 +87,18 @@ func clauseSatisfied(c *filer_pb.WriteCondition_Clause, current *filer.Entry) bo
|
||||
if !exists || c.ExpectedEntry == nil {
|
||||
return !exists && c.ExpectedEntry == nil
|
||||
}
|
||||
// Compare both sides in serialized form on clones: chunks are matched
|
||||
// by their fid only — the stored entry may carry the restored file_id
|
||||
// while an expected one built from a metadata event does not.
|
||||
expected := proto.Clone(c.ExpectedEntry).(*filer_pb.Entry)
|
||||
filer_pb.BeforeEntrySerialization(expected.Chunks)
|
||||
actual := proto.Clone(current.ToProtoEntry()).(*filer_pb.Entry)
|
||||
filer_pb.BeforeEntrySerialization(actual.Chunks)
|
||||
return proto.Equal(actual, filer.FromPbEntry("", expected).ToProtoEntry())
|
||||
// Compare both sides in canonical serialized form on clones: chunks are
|
||||
// matched by their fid only — the stored entry may carry the restored
|
||||
// file_id while an expected one built from a metadata event does not —
|
||||
// and the codec round-trip settles derived fields on both sides, like an
|
||||
// unset atime reading back as mtime.
|
||||
canonical := func(e *filer_pb.Entry) *filer_pb.Entry {
|
||||
filer_pb.BeforeEntrySerialization(e.Chunks)
|
||||
return filer.FromPbEntry("", e).ToProtoEntry()
|
||||
}
|
||||
expected := canonical(proto.Clone(c.ExpectedEntry).(*filer_pb.Entry))
|
||||
actual := canonical(proto.Clone(current.ToProtoEntry()).(*filer_pb.Entry))
|
||||
return proto.Equal(actual, expected)
|
||||
default:
|
||||
// An unrecognized clause kind (e.g. from a newer client) must not be
|
||||
// treated as satisfied, which would silently bypass the guard. Fail
|
||||
|
||||
Reference in new issue
Block a user