@@ -121,15 +121,16 @@ func (nf *UpdateFileChanger) ApplyChangeV2(ctx context.Context, allocationRoot,
121
121
122
122
//find if ref exists
123
123
var refResult struct {
124
- ID int64
125
- Type string
126
- NumUpdates int64 `gorm:"column:num_of_updates" json:"num_of_updates"`
127
- Size int64 `gorm:"column:size" json:"size"`
124
+ ID int64
125
+ Type string
126
+ NumUpdates int64 `gorm:"column:num_of_updates" json:"num_of_updates"`
127
+ Size int64 `gorm:"column:size" json:"size"`
128
+ FileMetaHash string `gorm:"column:file_meta_hash" json:"file_meta_hash"`
128
129
}
129
130
130
131
err := datastore .GetStore ().WithNewTransaction (func (ctx context.Context ) error {
131
132
tx := datastore .GetStore ().GetTransaction (ctx )
132
- return tx .Model (& reference.Ref {}).Select ("id" , "type" , "num_of_updates" , "size" ).Where ("lookup_hash = ?" , nf .LookupHash ).Take (& refResult ).Error
133
+ return tx .Model (& reference.Ref {}).Select ("id" , "type" , "num_of_updates" , "size" , "file_meta_hash" ).Where ("lookup_hash = ?" , nf .LookupHash ).Take (& refResult ).Error
133
134
}, & sql.TxOptions {
134
135
ReadOnly : true ,
135
136
})
@@ -187,9 +188,11 @@ func (nf *UpdateFileChanger) ApplyChangeV2(ctx context.Context, allocationRoot,
187
188
}
188
189
collector .DeleteRefRecord (deleteRecord )
189
190
collector .CreateRefRecord (newFile )
190
- decodedKey , _ := hex .DecodeString (newFile .LookupHash )
191
- decodedValue , _ := hex .DecodeString (newFile .FileMetaHash )
192
- err = trie .Update (decodedKey , decodedValue , uint64 (newFile .NumBlocks ))
191
+ if newFile .FileMetaHash != refResult .FileMetaHash {
192
+ decodedKey , _ := hex .DecodeString (newFile .LookupHash )
193
+ decodedValue , _ := hex .DecodeString (newFile .FileMetaHash )
194
+ err = trie .Update (decodedKey , decodedValue , uint64 (newFile .NumBlocks ))
195
+ }
193
196
return refResult .Size - newFile .Size , err
194
197
}
195
198
0 commit comments