@@ -19,10 +19,12 @@ import (
19
19
//checkIsValidRequest check if it a valid request in case of bad request it write the response to ctx.
20
20
func checkIsValidRequest (ctx * context.Context ) bool {
21
21
if ! setting .LFS .StartServer {
22
+ log .Debug ("Attempt to access LFS server but LFS server is disabled" )
22
23
writeStatus (ctx , 404 )
23
24
return false
24
25
}
25
26
if ! MetaMatcher (ctx .Req ) {
27
+ log .Info ("Attempt access LOCKs without accepting the correct media type: %s" , metaMediaType )
26
28
writeStatus (ctx , 400 )
27
29
return false
28
30
}
@@ -47,7 +49,7 @@ func handleLockListOut(ctx *context.Context, repo *models.Repository, lock *mode
47
49
return
48
50
}
49
51
ctx .JSON (500 , api.LFSLockError {
50
- Message : "unable to list locks : " + err . Error () ,
52
+ Message : "unable to list locks : Internal Server Error" ,
51
53
})
52
54
return
53
55
}
@@ -65,6 +67,7 @@ func handleLockListOut(ctx *context.Context, repo *models.Repository, lock *mode
65
67
// GetListLockHandler list locks
66
68
func GetListLockHandler (ctx * context.Context ) {
67
69
if ! checkIsValidRequest (ctx ) {
70
+ // Status is written in checkIsValidRequest
68
71
return
69
72
}
70
73
ctx .Resp .Header ().Set ("Content-Type" , metaMediaType )
@@ -87,7 +90,17 @@ func GetListLockHandler(ctx *context.Context) {
87
90
})
88
91
return
89
92
}
90
- //TODO handle query cursor and limit
93
+
94
+ cursor := ctx .QueryInt ("cursor" )
95
+ if cursor < 0 {
96
+ cursor = 0
97
+ }
98
+ limit := ctx .QueryInt ("limit" )
99
+ if limit > setting .LFS .LocksPagingNum && setting .LFS .LocksPagingNum > 0 {
100
+ limit = setting .LFS .LocksPagingNum
101
+ } else if limit < 0 {
102
+ limit = 0
103
+ }
91
104
id := ctx .Query ("id" )
92
105
if id != "" { //Case where we request a specific id
93
106
v , err := strconv .ParseInt (id , 10 , 64 )
@@ -98,37 +111,50 @@ func GetListLockHandler(ctx *context.Context) {
98
111
return
99
112
}
100
113
lock , err := models .GetLFSLockByID (v )
114
+ if err != nil && ! models .IsErrLFSLockNotExist (err ) {
115
+ log .Error ("Unable to get lock with ID[%s]: Error: %v" , v , err )
116
+ }
101
117
handleLockListOut (ctx , repository , lock , err )
102
118
return
103
119
}
104
120
105
121
path := ctx .Query ("path" )
106
122
if path != "" { //Case where we request a specific id
107
123
lock , err := models .GetLFSLock (repository , path )
124
+ if err != nil && ! models .IsErrLFSLockNotExist (err ) {
125
+ log .Error ("Unable to get lock for repository %-v with path %s: Error: %v" , repository , path , err )
126
+ }
108
127
handleLockListOut (ctx , repository , lock , err )
109
128
return
110
129
}
111
130
112
131
//If no query params path or id
113
- lockList , err := models .GetLFSLockByRepoID (repository .ID , 0 , 0 )
132
+ lockList , err := models .GetLFSLockByRepoID (repository .ID , cursor , limit )
114
133
if err != nil {
134
+ log .Error ("Unable to list locks for repository ID[%d]: Error: %v" , repository .ID , err )
115
135
ctx .JSON (500 , api.LFSLockError {
116
- Message : "unable to list locks : " + err . Error () ,
136
+ Message : "unable to list locks : Internal Server Error" ,
117
137
})
118
138
return
119
139
}
120
140
lockListAPI := make ([]* api.LFSLock , len (lockList ))
141
+ next := ""
121
142
for i , l := range lockList {
122
143
lockListAPI [i ] = l .APIFormat ()
123
144
}
145
+ if limit > 0 && len (lockList ) == limit {
146
+ next = strconv .Itoa (cursor + 1 )
147
+ }
124
148
ctx .JSON (200 , api.LFSLockList {
125
149
Locks : lockListAPI ,
150
+ Next : next ,
126
151
})
127
152
}
128
153
129
154
// PostLockHandler create lock
130
155
func PostLockHandler (ctx * context.Context ) {
131
156
if ! checkIsValidRequest (ctx ) {
157
+ // Status is written in checkIsValidRequest
132
158
return
133
159
}
134
160
ctx .Resp .Header ().Set ("Content-Type" , metaMediaType )
@@ -139,7 +165,7 @@ func PostLockHandler(ctx *context.Context) {
139
165
140
166
repository , err := models .GetRepositoryByOwnerAndName (userName , repoName )
141
167
if err != nil {
142
- log .Debug ( "Could not find repository: %s/%s - %s " , userName , repoName , err )
168
+ log .Error ( "Unable to get repository: %s/%s Error: %v " , userName , repoName , err )
143
169
writeStatus (ctx , 404 )
144
170
return
145
171
}
@@ -159,6 +185,7 @@ func PostLockHandler(ctx *context.Context) {
159
185
defer bodyReader .Close ()
160
186
dec := json .NewDecoder (bodyReader )
161
187
if err := dec .Decode (& req ); err != nil {
188
+ log .Warn ("Failed to decode lock request as json. Error: %v" , err )
162
189
writeStatus (ctx , 400 )
163
190
return
164
191
}
@@ -183,8 +210,9 @@ func PostLockHandler(ctx *context.Context) {
183
210
})
184
211
return
185
212
}
213
+ log .Error ("Unable to CreateLFSLock in repository %-v at %s for user %-v: Error: %v" , repository , req .Path , ctx .User , err )
186
214
ctx .JSON (500 , api.LFSLockError {
187
- Message : "internal server error : " + err . Error () ,
215
+ Message : "internal server error : Internal Server Error" ,
188
216
})
189
217
return
190
218
}
@@ -194,6 +222,7 @@ func PostLockHandler(ctx *context.Context) {
194
222
// VerifyLockHandler list locks for verification
195
223
func VerifyLockHandler (ctx * context.Context ) {
196
224
if ! checkIsValidRequest (ctx ) {
225
+ // Status is written in checkIsValidRequest
197
226
return
198
227
}
199
228
ctx .Resp .Header ().Set ("Content-Type" , metaMediaType )
@@ -204,7 +233,7 @@ func VerifyLockHandler(ctx *context.Context) {
204
233
205
234
repository , err := models .GetRepositoryByOwnerAndName (userName , repoName )
206
235
if err != nil {
207
- log .Debug ( "Could not find repository: %s/%s - %s " , userName , repoName , err )
236
+ log .Error ( "Unable to get repository: %s/%s Error: %v " , userName , repoName , err )
208
237
writeStatus (ctx , 404 )
209
238
return
210
239
}
@@ -219,14 +248,28 @@ func VerifyLockHandler(ctx *context.Context) {
219
248
return
220
249
}
221
250
222
- //TODO handle body json cursor and limit
223
- lockList , err := models .GetLFSLockByRepoID (repository .ID , 0 , 0 )
251
+ cursor := ctx .QueryInt ("cursor" )
252
+ if cursor < 0 {
253
+ cursor = 0
254
+ }
255
+ limit := ctx .QueryInt ("limit" )
256
+ if limit > setting .LFS .LocksPagingNum && setting .LFS .LocksPagingNum > 0 {
257
+ limit = setting .LFS .LocksPagingNum
258
+ } else if limit < 0 {
259
+ limit = 0
260
+ }
261
+ lockList , err := models .GetLFSLockByRepoID (repository .ID , cursor , limit )
224
262
if err != nil {
263
+ log .Error ("Unable to list locks for repository ID[%d]: Error: %v" , repository .ID , err )
225
264
ctx .JSON (500 , api.LFSLockError {
226
- Message : "unable to list locks : " + err . Error () ,
265
+ Message : "unable to list locks : Internal Server Error" ,
227
266
})
228
267
return
229
268
}
269
+ next := ""
270
+ if limit > 0 && len (lockList ) == limit {
271
+ next = strconv .Itoa (cursor + 1 )
272
+ }
230
273
lockOursListAPI := make ([]* api.LFSLock , 0 , len (lockList ))
231
274
lockTheirsListAPI := make ([]* api.LFSLock , 0 , len (lockList ))
232
275
for _ , l := range lockList {
@@ -239,12 +282,14 @@ func VerifyLockHandler(ctx *context.Context) {
239
282
ctx .JSON (200 , api.LFSLockListVerify {
240
283
Ours : lockOursListAPI ,
241
284
Theirs : lockTheirsListAPI ,
285
+ Next : next ,
242
286
})
243
287
}
244
288
245
289
// UnLockHandler delete locks
246
290
func UnLockHandler (ctx * context.Context ) {
247
291
if ! checkIsValidRequest (ctx ) {
292
+ // Status is written in checkIsValidRequest
248
293
return
249
294
}
250
295
ctx .Resp .Header ().Set ("Content-Type" , metaMediaType )
@@ -255,7 +300,7 @@ func UnLockHandler(ctx *context.Context) {
255
300
256
301
repository , err := models .GetRepositoryByOwnerAndName (userName , repoName )
257
302
if err != nil {
258
- log .Debug ( "Could not find repository: %s/%s - %s " , userName , repoName , err )
303
+ log .Error ( "Unable to get repository: %s/%s Error: %v " , userName , repoName , err )
259
304
writeStatus (ctx , 404 )
260
305
return
261
306
}
@@ -275,6 +320,7 @@ func UnLockHandler(ctx *context.Context) {
275
320
defer bodyReader .Close ()
276
321
dec := json .NewDecoder (bodyReader )
277
322
if err := dec .Decode (& req ); err != nil {
323
+ log .Warn ("Failed to decode lock request as json. Error: %v" , err )
278
324
writeStatus (ctx , 400 )
279
325
return
280
326
}
@@ -288,8 +334,9 @@ func UnLockHandler(ctx *context.Context) {
288
334
})
289
335
return
290
336
}
337
+ log .Error ("Unable to DeleteLFSLockByID[%d] by user %-v with force %t: Error: %v" , ctx .ParamsInt64 ("lid" ), ctx .User , req .Force , err )
291
338
ctx .JSON (500 , api.LFSLockError {
292
- Message : "unable to delete lock : " + err . Error () ,
339
+ Message : "unable to delete lock : Internal Server Error" ,
293
340
})
294
341
return
295
342
}
0 commit comments