Stop stops the sync process
(fatalError error)
| 411 | |
| 412 | // Stop stops the sync process |
| 413 | func (s *Sync) Stop(fatalError error) { |
| 414 | s.stopOnce.Do(func() { |
| 415 | s.cancelCtx() |
| 416 | if s.upstream != nil { |
| 417 | for _, symlink := range s.upstream.symlinks { |
| 418 | symlink.Stop() |
| 419 | } |
| 420 | if s.upstream.writer != nil { |
| 421 | s.upstream.writer.Close() |
| 422 | } |
| 423 | if s.upstream.reader != nil { |
| 424 | s.upstream.reader.Close() |
| 425 | } |
| 426 | if s.upstream.conn != nil { |
| 427 | s.upstream.conn.Close() |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | if s.downstream != nil { |
| 432 | if s.downstream.writer != nil { |
| 433 | s.downstream.writer.Close() |
| 434 | } |
| 435 | if s.downstream.reader != nil { |
| 436 | s.downstream.reader.Close() |
| 437 | } |
| 438 | if s.downstream.conn != nil { |
| 439 | s.downstream.conn.Close() |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | if fatalError != nil { |
| 444 | s.Error(fatalError) |
| 445 | |
| 446 | // This needs to be rethought because we do not always kill the application here, would be better to have an error channel |
| 447 | // or runtime error here |
| 448 | if s.onError != nil { |
| 449 | s.onError <- fatalError |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | s.log.Debugf("Sync stopped") |
| 454 | if s.onDone != nil { |
| 455 | close(s.onDone) |
| 456 | } |
| 457 | }) |
| 458 | } |
no test coverage detected