@@ -656,11 +656,6 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
656656 return nil , common .NewError ("invalid_operation" , "Operation needs to be performed by the owner of the allocation" )
657657 }
658658
659- if allocationObj .BlobberSizeUsed + connectionObj .Size > allocationObj .BlobberSize {
660- return nil , common .NewError ("max_allocation_size" ,
661- "Max size reached for the allocation with this blobber" )
662- }
663-
664659 writeMarkerString := r .FormValue ("write_marker" )
665660 if writeMarkerString == "" {
666661 return nil , common .NewError ("invalid_parameters" , "Invalid write marker passed" )
@@ -689,11 +684,6 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
689684 "Latest write marker is in failed state" )
690685 }
691686
692- if latestWriteMarkerEntity .WM .ChainSize + connectionObj .Size != writeMarker .ChainSize {
693- return nil , common .NewErrorf ("invalid_chain_size" ,
694- "Invalid chain size. expected:%v got %v" , latestWriteMarkerEntity .WM .ChainSize + connectionObj .Size , writeMarker .ChainSize )
695- }
696-
697687 if latestWriteMarkerEntity .Status != writemarker .Committed {
698688 writeMarker .ChainLength = latestWriteMarkerEntity .WM .ChainLength
699689 }
@@ -758,6 +748,24 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
758748 if ! rootRef .IsPrecommit {
759749 return nil , common .NewError ("no_root_change" , "No change in root ref" )
760750 }
751+ connectionObj .Size = rootRef .Size - allocationObj .BlobberSizeUsed
752+
753+ if writemarkerEntity .WM .Size != connectionObj .Size {
754+ return nil , common .NewError ("write_marker_validation_failed" , fmt .Sprintf ("Write Marker size %v does not match the connection size %v" , writemarkerEntity .WM .Size , connectionObj .Size ))
755+ }
756+
757+ if allocationObj .BlobberSizeUsed + connectionObj .Size > allocationObj .BlobberSize {
758+ return nil , common .NewError ("max_allocation_size" ,
759+ "Max size reached for the allocation with this blobber" )
760+ }
761+
762+ if latestWriteMarkerEntity != nil && latestWriteMarkerEntity .WM .ChainSize + connectionObj .Size != writeMarker .ChainSize {
763+ return nil , common .NewErrorf ("invalid_chain_size" ,
764+ "Invalid chain size. expected:%v got %v" , latestWriteMarkerEntity .WM .ChainSize + connectionObj .Size , writeMarker .ChainSize )
765+ } else if latestWriteMarkerEntity == nil && connectionObj .Size != writeMarker .ChainSize {
766+ return nil , common .NewErrorf ("invalid_chain_size" ,
767+ "Invalid chain size. expected:%v got %v" , connectionObj .Size , writeMarker .ChainSize )
768+ }
761769
762770 elapsedApplyChanges := time .Since (startTime ) - elapsedAllocation - elapsedGetLock -
763771 elapsedGetConnObj - elapsedVerifyWM - elapsedWritePreRedeem
@@ -1245,6 +1253,8 @@ func (fsh *StorageHandler) CreateDir(ctx context.Context, r *http.Request) (*all
12451253 return nil , common .NewError ("invalid_parameters" , "Invalid dir path passed" )
12461254 }
12471255
1256+ customMeta := r .FormValue ("custom_meta" )
1257+
12481258 exisitingRef , err := fsh .checkIfFileAlreadyExists (ctx , allocationID , dirPath )
12491259 if err != nil {
12501260 Logger .Error ("Error file reference" , zap .Error (err ))
@@ -1257,6 +1267,16 @@ func (fsh *StorageHandler) CreateDir(ctx context.Context, r *http.Request) (*all
12571267 if exisitingRef != nil {
12581268 // target directory exists, return StatusOK
12591269 if exisitingRef .Type == reference .DIRECTORY {
1270+
1271+ if exisitingRef .CustomMeta != customMeta {
1272+ _ = datastore .GetStore ().WithNewTransaction (func (ctx context.Context ) error {
1273+ err := reference .UpdateCustomMeta (ctx , exisitingRef , customMeta )
1274+ if err != nil {
1275+ logging .Logger .Error ("Error updating custom meta" , zap .Error (err ))
1276+ }
1277+ return err
1278+ })
1279+ }
12601280 return nil , common .NewError ("directory_exists" , "Directory already exists`" )
12611281 }
12621282
@@ -1293,6 +1313,7 @@ func (fsh *StorageHandler) CreateDir(ctx context.Context, r *http.Request) (*all
12931313 newDir .ConnectionID = connectionID
12941314 newDir .Path = dirPath
12951315 newDir .AllocationID = allocationID
1316+ newDir .CustomMeta = customMeta
12961317
12971318 connectionObj .AddChange (allocationChange , & newDir )
12981319
0 commit comments