@@ -203,7 +203,10 @@ func BatchHandler(ctx *context.Context) {
203
203
204
204
for _ , p := range br .Objects {
205
205
if ! p .IsValid () {
206
- responseObjects = append (responseObjects , buildObjectResponse (rc , p , false , false , http .StatusUnprocessableEntity ))
206
+ responseObjects = append (responseObjects , buildObjectResponse (rc , p , false , false , & lfs_module.ObjectError {
207
+ Code : http .StatusUnprocessableEntity ,
208
+ Message : "Oid or size are invalid" ,
209
+ }))
207
210
continue
208
211
}
209
212
@@ -221,6 +224,14 @@ func BatchHandler(ctx *context.Context) {
221
224
return
222
225
}
223
226
227
+ if meta != nil && p .Size != meta .Size {
228
+ responseObjects = append (responseObjects , buildObjectResponse (rc , p , false , false , & lfs_module.ObjectError {
229
+ Code : http .StatusUnprocessableEntity ,
230
+ Message : fmt .Sprintf ("Object %s is not %d bytes" , p .Oid , p .Size ),
231
+ }))
232
+ continue
233
+ }
234
+
224
235
var responseObject * lfs_module.ObjectResponse
225
236
if isUpload {
226
237
if ! exists && setting .LFS .MaxFileSize > 0 && p .Size > setting .LFS .MaxFileSize {
@@ -240,16 +251,17 @@ func BatchHandler(ctx *context.Context) {
240
251
}
241
252
}
242
253
243
- responseObject = buildObjectResponse (rc , p , false , ! exists , 0 )
254
+ responseObject = buildObjectResponse (rc , p , false , ! exists , nil )
244
255
} else {
245
- errorCode := 0
256
+ var err * lfs_module. ObjectError
246
257
if ! exists || meta == nil {
247
- errorCode = http .StatusNotFound
248
- } else if meta .Size != p .Size {
249
- errorCode = http .StatusUnprocessableEntity
258
+ err = & lfs_module.ObjectError {
259
+ Code : http .StatusNotFound ,
260
+ Message : http .StatusText (http .StatusNotFound ),
261
+ }
250
262
}
251
263
252
- responseObject = buildObjectResponse (rc , p , true , false , errorCode )
264
+ responseObject = buildObjectResponse (rc , p , true , false , err )
253
265
}
254
266
responseObjects = append (responseObjects , responseObject )
255
267
}
@@ -333,13 +345,10 @@ func getRequestContext(ctx *context.Context) *requestContext {
333
345
}
334
346
}
335
347
336
- func buildObjectResponse (rc * requestContext , pointer lfs_module.Pointer , download , upload bool , errorCode int ) * lfs_module.ObjectResponse {
348
+ func buildObjectResponse (rc * requestContext , pointer lfs_module.Pointer , download , upload bool , err * lfs_module. ObjectError ) * lfs_module.ObjectResponse {
337
349
rep := & lfs_module.ObjectResponse {Pointer : pointer }
338
- if errorCode > 0 {
339
- rep .Error = & lfs_module.ObjectError {
340
- Code : errorCode ,
341
- Message : http .StatusText (errorCode ),
342
- }
350
+ if err != nil {
351
+ rep .Error = err
343
352
} else {
344
353
rep .Actions = make (map [string ]* lfs_module.Link )
345
354
0 commit comments