@@ -94,6 +94,22 @@ func containsString(slice []string, s string) bool {
94
94
return false
95
95
}
96
96
97
+ //nolint:unused
98
+ func (s * Server ) getFSManagerForBranch (branchName string ) (pool.FSManager , error ) {
99
+ allBranches , err := s .pm .First ().ListAllBranches ()
100
+ if err != nil {
101
+ return nil , fmt .Errorf ("failed to get branch list: %w" , err )
102
+ }
103
+
104
+ for _ , branchEntity := range allBranches {
105
+ if branchEntity .Name == branchName {
106
+ return s .getFSManagerForSnapshot (branchEntity .SnapshotID )
107
+ }
108
+ }
109
+
110
+ return nil , fmt .Errorf ("failed to found dataset of the branch: %s" , branchName )
111
+ }
112
+
97
113
func (s * Server ) createBranch (w http.ResponseWriter , r * http.Request ) {
98
114
var createRequest types.BranchCreateRequest
99
115
if err := api .ReadJSON (r , & createRequest ); err != nil {
@@ -111,10 +127,20 @@ func (s *Server) createBranch(w http.ResponseWriter, r *http.Request) {
111
127
return
112
128
}
113
129
130
+ var err error
131
+
114
132
fsm := s .pm .First ()
115
133
134
+ if createRequest .BaseBranch != "" {
135
+ fsm , err = s .getFSManagerForBranch (createRequest .BaseBranch )
136
+ if err != nil {
137
+ api .SendBadRequestError (w , r , err .Error ())
138
+ return
139
+ }
140
+ }
141
+
116
142
if fsm == nil {
117
- api .SendBadRequestError (w , r , "no available pools " )
143
+ api .SendBadRequestError (w , r , "no pool manager found " )
118
144
return
119
145
}
120
146
@@ -197,10 +223,9 @@ func (s *Server) getCommit(w http.ResponseWriter, r *http.Request) {
197
223
return
198
224
}
199
225
200
- fsm := s .pm .First ()
201
-
202
- if fsm == nil {
203
- api .SendBadRequestError (w , r , "no available pools" )
226
+ fsm , err := s .getFSManagerForSnapshot (snapshotID )
227
+ if err != nil {
228
+ api .SendBadRequestError (w , r , err .Error ())
204
229
return
205
230
}
206
231
@@ -223,6 +248,20 @@ func (s *Server) getCommit(w http.ResponseWriter, r *http.Request) {
223
248
}
224
249
}
225
250
251
+ func (s * Server ) getFSManagerForSnapshot (snapshotID string ) (pool.FSManager , error ) {
252
+ poolName , err := s .detectPoolName (snapshotID )
253
+ if err != nil {
254
+ return nil , fmt .Errorf ("failed to detect pool name for the snapshot %s: %w" , snapshotID , err )
255
+ }
256
+
257
+ fsm , err := s .pm .GetFSManager (poolName )
258
+ if err != nil {
259
+ return nil , fmt .Errorf ("pool manager not available %s: %w" , poolName , err )
260
+ }
261
+
262
+ return fsm , nil
263
+ }
264
+
226
265
func (s * Server ) snapshot (w http.ResponseWriter , r * http.Request ) {
227
266
var snapshotRequest types.SnapshotCloneCreateRequest
228
267
if err := api .ReadJSON (r , & snapshotRequest ); err != nil {
@@ -325,19 +364,23 @@ func (s *Server) snapshot(w http.ResponseWriter, r *http.Request) {
325
364
}
326
365
327
366
func (s * Server ) log (w http.ResponseWriter , r * http.Request ) {
328
- fsm := s .pm .First ()
329
-
330
- if fsm == nil {
331
- api .SendBadRequestError (w , r , "no available pools" )
367
+ var logRequest types.LogRequest
368
+ if err := api .ReadJSON (r , & logRequest ); err != nil {
369
+ api .SendBadRequestError (w , r , err .Error ())
332
370
return
333
371
}
334
372
335
- var logRequest types. LogRequest
336
- if err := api . ReadJSON ( r , & logRequest ); err != nil {
373
+ fsm , err := s . getFSManagerForBranch ( logRequest . BranchName )
374
+ if err != nil {
337
375
api .SendBadRequestError (w , r , err .Error ())
338
376
return
339
377
}
340
378
379
+ if fsm == nil {
380
+ api .SendBadRequestError (w , r , "no pool manager found" )
381
+ return
382
+ }
383
+
341
384
repo , err := fsm .GetRepo ()
342
385
if err != nil {
343
386
api .SendBadRequestError (w , r , err .Error ())
@@ -377,10 +420,14 @@ func (s *Server) deleteBranch(w http.ResponseWriter, r *http.Request) {
377
420
return
378
421
}
379
422
380
- fsm := s .pm .First ()
423
+ fsm , err := s .getFSManagerForBranch (deleteRequest .BranchName )
424
+ if err != nil {
425
+ api .SendBadRequestError (w , r , err .Error ())
426
+ return
427
+ }
381
428
382
429
if fsm == nil {
383
- api .SendBadRequestError (w , r , "no available pools " )
430
+ api .SendBadRequestError (w , r , "no pool manager found " )
384
431
return
385
432
}
386
433
0 commit comments