@@ -142,7 +142,7 @@ func (c *baseCloning) CreateClone(cloneRequest *types.CloneCreateRequest) (*mode
142142 // TODO(anatoly): Empty room case.
143143 log .Errf ("Failed to start session: %v." , err )
144144
145- if updateErr := c .updateCloneStatus (cloneID , models.Status {
145+ if updateErr := c .UpdateCloneStatus (cloneID , models.Status {
146146 Code : models .StatusFatal ,
147147 Message : errors .Cause (err ).Error (),
148148 }); updateErr != nil {
@@ -196,7 +196,7 @@ func (c *baseCloning) DestroyClone(cloneID string) error {
196196 return models .New (models .ErrCodeBadRequest , "clone is protected" )
197197 }
198198
199- if err := c .updateCloneStatus (cloneID , models.Status {
199+ if err := c .UpdateCloneStatus (cloneID , models.Status {
200200 Code : models .StatusDeleting ,
201201 Message : models .CloneMessageDeleting ,
202202 }); err != nil {
@@ -213,7 +213,7 @@ func (c *baseCloning) DestroyClone(cloneID string) error {
213213 if err := c .provision .StopSession (w .session ); err != nil {
214214 log .Errf ("Failed to delete a clone: %+v." , err )
215215
216- if updateErr := c .updateCloneStatus (cloneID , models.Status {
216+ if updateErr := c .UpdateCloneStatus (cloneID , models.Status {
217217 Code : models .StatusFatal ,
218218 Message : errors .Cause (err ).Error (),
219219 }); updateErr != nil {
@@ -271,17 +271,32 @@ func (c *baseCloning) UpdateClone(id string, patch *types.CloneUpdateRequest) (*
271271 return clone , nil
272272}
273273
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+
274289func (c * baseCloning ) ResetClone (cloneID string ) error {
275290 w , ok := c .findWrapper (cloneID )
276291 if ! ok {
277- return models .New (models .ErrCodeNotFound , "clone not found" )
292+ return models .New (models .ErrCodeNotFound , "the clone not found" )
278293 }
279294
280295 if w .session == nil {
281296 return models .New (models .ErrCodeNotFound , "clone is not started yet" )
282297 }
283298
284- if err := c .updateCloneStatus (cloneID , models.Status {
299+ if err := c .UpdateCloneStatus (cloneID , models.Status {
285300 Code : models .StatusResetting ,
286301 Message : models .CloneMessageResetting ,
287302 }); err != nil {
@@ -293,7 +308,7 @@ func (c *baseCloning) ResetClone(cloneID string) error {
293308 if err != nil {
294309 log .Errf ("Failed to reset a clone: %+v." , err )
295310
296- if updateErr := c .updateCloneStatus (cloneID , models.Status {
311+ if updateErr := c .UpdateCloneStatus (cloneID , models.Status {
297312 Code : models .StatusFatal ,
298313 Message : errors .Cause (err ).Error (),
299314 }); updateErr != nil {
@@ -303,7 +318,7 @@ func (c *baseCloning) ResetClone(cloneID string) error {
303318 return
304319 }
305320
306- if err := c .updateCloneStatus (cloneID , models.Status {
321+ if err := c .UpdateCloneStatus (cloneID , models.Status {
307322 Code : models .StatusOK ,
308323 Message : models .CloneMessageOK ,
309324 }); err != nil {
@@ -379,21 +394,6 @@ func (c *baseCloning) setWrapper(id string, wrapper *CloneWrapper) {
379394 c .cloneMutex .Unlock ()
380395}
381396
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-
397397// deleteClone removes the clone by ID.
398398func (c * baseCloning ) deleteClone (cloneID string ) {
399399 c .cloneMutex .Lock ()
0 commit comments