@@ -269,11 +269,7 @@ func BatchHandler(ctx *context.Context) {
269
269
return
270
270
}
271
271
272
- reqCtx := & requestContext {
273
- User : ctx .Params ("username" ),
274
- Repo : strings .TrimSuffix (ctx .Params ("reponame" ), ".git" ),
275
- Authorization : ctx .Req .Header .Get ("Authorization" ),
276
- }
272
+ reqCtx := getRequestContext (ctx )
277
273
278
274
repository , err := models .GetRepositoryByOwnerAndName (reqCtx .User , reqCtx .Repo )
279
275
if err != nil {
@@ -291,55 +287,55 @@ func BatchHandler(ctx *context.Context) {
291
287
292
288
var responseObjects []* lfs_module.ObjectResponse
293
289
294
- for _ , object := range bv .Objects {
290
+ for _ , p := range bv .Objects {
295
291
if ! object .IsValid () {
296
- responseObjects = append (responseObjects , buildDownloadObjectResponse (reqCtx , object , http .StatusUnprocessableEntity ))
292
+ responseObjects = append (responseObjects , buildObjectResponse (reqCtx , p , false , false , http .StatusUnprocessableEntity ))
297
293
continue
298
294
}
299
295
300
- exist , err := contentStore .Exists (object )
296
+ exists , err := contentStore .Exists (p )
301
297
if err != nil {
302
- log .Error ("Unable to check if LFS OID[%s] exist on %s/%s. Error: %v" , object .Oid , reqCtx .User , reqCtx .Repo , err )
298
+ log .Error ("Unable to check if LFS OID[%s] exist on %s/%s. Error: %v" , p .Oid , reqCtx .User , reqCtx .Repo , err )
303
299
writeStatus (ctx , http .StatusInternalServerError )
304
300
return
305
301
}
306
302
307
- meta , metaErr := repository .GetLFSMetaObjectByOid (object .Oid )
303
+ meta , metaErr := repository .GetLFSMetaObjectByOid (p .Oid )
308
304
if metaErr != nil && metaErr != models .ErrLFSObjectNotExist {
309
- log .Error ("Unable to get LFS MetaObject [%s] for %s/%s. Error: %v" , object .Oid , reqCtx .User , reqCtx .Repo , metaErr )
305
+ log .Error ("Unable to get LFS MetaObject [%s] for %s/%s. Error: %v" , p .Oid , reqCtx .User , reqCtx .Repo , metaErr )
310
306
writeStatus (ctx , http .StatusInternalServerError )
311
307
return
312
308
}
313
309
314
310
var responseObject * lfs_module.ObjectResponse
315
311
if isUpload {
316
312
if ! exists && setting .LFS .MaxFileSize > 0 && object .Size > setting .LFS .MaxFileSize {
317
- log .Info ("Denied LFS OID[%s] upload of size %d to %s/%s because of LFS_MAX_FILE_SIZE=%d" , object .Oid , object .Size , reqCtx .User , reqCtx .Repo , setting .LFS .MaxFileSize )
313
+ log .Info ("Denied LFS OID[%s] upload of size %d to %s/%s because of LFS_MAX_FILE_SIZE=%d" , p .Oid , p .Size , reqCtx .User , reqCtx .Repo , setting .LFS .MaxFileSize )
318
314
writeStatus (ctx , http .StatusRequestEntityTooLarge )
319
315
return
320
316
}
321
317
322
318
if exists {
323
319
if meta == nil {
324
- _ , err := models .NewLFSMetaObject (& models.LFSMetaObject {Pointer : object , RepositoryID : repository .ID })
320
+ _ , err := models .NewLFSMetaObject (& models.LFSMetaObject {Pointer : p , RepositoryID : repository .ID })
325
321
if err != nil {
326
- log .Error ("Unable to create LFS MetaObject [%s] for %s/%s. Error: %v" , object .Oid , reqCtx .User , reqCtx .Repo , metaErr )
322
+ log .Error ("Unable to create LFS MetaObject [%s] for %s/%s. Error: %v" , p .Oid , reqCtx .User , reqCtx .Repo , metaErr )
327
323
writeStatus (ctx , http .StatusInternalServerError )
328
324
return
329
325
}
330
326
}
331
327
}
332
328
333
- responseObject = buildObjectResponse (reqCtx , object , false , ! exists , 0 )
329
+ responseObject = buildObjectResponse (reqCtx , p , false , ! exists , 0 )
334
330
} else {
335
331
errorCode := 0
336
- if ! exist || meta == nil {
332
+ if ! exists || meta == nil {
337
333
errorCode = http .StatusNotFound
338
- } else if meta .Size != object .Size {
334
+ } else if meta .Size != p .Size {
339
335
errorCode = http .StatusUnprocessableEntity
340
336
}
341
337
342
- responseObject = buildObjectResponse (reqCtx , object , true , false , errorCode )
338
+ responseObject = buildObjectResponse (reqCtx , p , true , false , errorCode )
343
339
}
344
340
responseObjects = append (responseObjects , responseObject )
345
341
}
@@ -397,7 +393,6 @@ func VerifyHandler(ctx *context.Context) {
397
393
398
394
meta , _ := getAuthenticatedRepoAndMeta (ctx , rc , p , true )
399
395
if meta == nil {
400
- // Status already written in getAuthenticatedRepoAndMeta
401
396
return
402
397
}
403
398
@@ -409,27 +404,35 @@ func VerifyHandler(ctx *context.Context) {
409
404
fmt .Fprintf (ctx .Resp , `{"message":"Internal Server Error"}` )
410
405
return
411
406
}
407
+
408
+ status := http .StatusOK
412
409
if ! ok {
413
- writeStatus (ctx , http .StatusUnprocessableEntity )
414
- return
410
+ status = http .StatusUnprocessableEntity
415
411
}
412
+ writeStatus (ctx , status )
413
+ }
416
414
417
- logRequest (ctx .Req , http .StatusOK )
415
+ func getRequestContext (ctx * context.Context ) * requestContext {
416
+ return & requestContext {
417
+ User : ctx .Params ("username" ),
418
+ Repo : strings .TrimSuffix (ctx .Params ("reponame" ), ".git" ),
419
+ Authorization : ctx .Req .Header .Get ("Authorization" ),
420
+ }
418
421
}
419
422
420
423
func buildObjectResponse (rc * requestContext , pointer lfs_module.Pointer , download , upload bool , errorCode int ) * lfs_module.ObjectResponse {
421
424
rep := & lfs_module.ObjectResponse {Pointer : pointer }
422
425
if errorCode > 0 {
423
- rep .Error = & ObjectError {
424
- Code : errorCode ,
426
+ rep .Error = & lfs_module. ObjectError {
427
+ Code : errorCode ,
425
428
Message : http .StatusText (errorCode ),
426
429
}
427
430
} else {
428
431
rep .Actions = make (map [string ]* lfs_module.Link )
429
432
430
433
header := make (map [string ]string )
431
434
verifyHeader := make (map [string ]string )
432
-
435
+
433
436
if len (rc .Authorization ) > 0 {
434
437
header ["Authorization" ] = rc .Authorization
435
438
verifyHeader ["Authorization" ] = rc .Authorization
@@ -455,17 +458,12 @@ func isValidAccept(r *http.Request) bool {
455
458
}
456
459
457
460
func unpack (ctx * context.Context ) (* requestContext , lfs_module.Pointer ) {
458
- r := ctx .Req
459
- rc := & requestContext {
460
- User : ctx .Params ("username" ),
461
- Repo : strings .TrimSuffix (ctx .Params ("reponame" ), ".git" ),
462
- Authorization : r .Header .Get ("Authorization" ),
463
- }
461
+ rc := getRequestContext (ctx )
464
462
p := lfs_module.Pointer {Oid : ctx .Params ("oid" )}
465
463
466
- if r .Method == "POST" { // Maybe also check if +json
464
+ if ctx . Req .Method == "POST" { // Maybe also check if +json
467
465
var p2 lfs_module.Pointer
468
- bodyReader := r .Body
466
+ bodyReader := ctx . Req .Body
469
467
defer bodyReader .Close ()
470
468
json := jsoniter .ConfigCompatibleWithStandardLibrary
471
469
dec := json .NewDecoder (bodyReader )
0 commit comments