@@ -142,7 +142,7 @@ func (c *baseCloning) CreateClone(cloneRequest *types.CloneCreateRequest) (*mode
142
142
// TODO(anatoly): Empty room case.
143
143
log .Errf ("Failed to start session: %v." , err )
144
144
145
- if updateErr := c .updateCloneStatus (cloneID , models.Status {
145
+ if updateErr := c .UpdateCloneStatus (cloneID , models.Status {
146
146
Code : models .StatusFatal ,
147
147
Message : errors .Cause (err ).Error (),
148
148
}); updateErr != nil {
@@ -196,7 +196,7 @@ func (c *baseCloning) DestroyClone(cloneID string) error {
196
196
return models .New (models .ErrCodeBadRequest , "clone is protected" )
197
197
}
198
198
199
- if err := c .updateCloneStatus (cloneID , models.Status {
199
+ if err := c .UpdateCloneStatus (cloneID , models.Status {
200
200
Code : models .StatusDeleting ,
201
201
Message : models .CloneMessageDeleting ,
202
202
}); err != nil {
@@ -213,7 +213,7 @@ func (c *baseCloning) DestroyClone(cloneID string) error {
213
213
if err := c .provision .StopSession (w .session ); err != nil {
214
214
log .Errf ("Failed to delete a clone: %+v." , err )
215
215
216
- if updateErr := c .updateCloneStatus (cloneID , models.Status {
216
+ if updateErr := c .UpdateCloneStatus (cloneID , models.Status {
217
217
Code : models .StatusFatal ,
218
218
Message : errors .Cause (err ).Error (),
219
219
}); updateErr != nil {
@@ -271,17 +271,32 @@ func (c *baseCloning) UpdateClone(id string, patch *types.CloneUpdateRequest) (*
271
271
return clone , nil
272
272
}
273
273
274
+ // UpdateCloneStatus updates the clone status.
275
+ func (c * baseCloning ) UpdateCloneStatus (cloneID string , status models.Status ) error {
276
+ c .cloneMutex .Lock ()
277
+ defer c .cloneMutex .Unlock ()
278
+
279
+ w , ok := c .clones [cloneID ]
280
+ if ! ok {
281
+ return errors .Errorf ("clone %q not found" , cloneID )
282
+ }
283
+
284
+ w .clone .Status = status
285
+
286
+ return nil
287
+ }
288
+
274
289
func (c * baseCloning ) ResetClone (cloneID string ) error {
275
290
w , ok := c .findWrapper (cloneID )
276
291
if ! ok {
277
- return models .New (models .ErrCodeNotFound , "clone not found" )
292
+ return models .New (models .ErrCodeNotFound , "the clone not found" )
278
293
}
279
294
280
295
if w .session == nil {
281
296
return models .New (models .ErrCodeNotFound , "clone is not started yet" )
282
297
}
283
298
284
- if err := c .updateCloneStatus (cloneID , models.Status {
299
+ if err := c .UpdateCloneStatus (cloneID , models.Status {
285
300
Code : models .StatusResetting ,
286
301
Message : models .CloneMessageResetting ,
287
302
}); err != nil {
@@ -293,7 +308,7 @@ func (c *baseCloning) ResetClone(cloneID string) error {
293
308
if err != nil {
294
309
log .Errf ("Failed to reset a clone: %+v." , err )
295
310
296
- if updateErr := c .updateCloneStatus (cloneID , models.Status {
311
+ if updateErr := c .UpdateCloneStatus (cloneID , models.Status {
297
312
Code : models .StatusFatal ,
298
313
Message : errors .Cause (err ).Error (),
299
314
}); updateErr != nil {
@@ -303,7 +318,7 @@ func (c *baseCloning) ResetClone(cloneID string) error {
303
318
return
304
319
}
305
320
306
- if err := c .updateCloneStatus (cloneID , models.Status {
321
+ if err := c .UpdateCloneStatus (cloneID , models.Status {
307
322
Code : models .StatusOK ,
308
323
Message : models .CloneMessageOK ,
309
324
}); err != nil {
@@ -379,21 +394,6 @@ func (c *baseCloning) setWrapper(id string, wrapper *CloneWrapper) {
379
394
c .cloneMutex .Unlock ()
380
395
}
381
396
382
- // updateCloneStatus updates the clone status.
383
- func (c * baseCloning ) updateCloneStatus (cloneID string , status models.Status ) error {
384
- c .cloneMutex .Lock ()
385
- defer c .cloneMutex .Unlock ()
386
-
387
- w , ok := c .clones [cloneID ]
388
- if ! ok {
389
- return errors .Errorf ("clone %q not found" , cloneID )
390
- }
391
-
392
- w .clone .Status = status
393
-
394
- return nil
395
- }
396
-
397
397
// deleteClone removes the clone by ID.
398
398
func (c * baseCloning ) deleteClone (cloneID string ) {
399
399
c .cloneMutex .Lock ()
0 commit comments