MCPcopy Index your code
hub / github.com/kopia/kopia / SetRepository

Method SetRepository

internal/server/server.go:602–657  ·  view source on GitHub ↗

SetRepository sets the repository (nil is allowed and indicates server that is not connected to the repository).

(ctx context.Context, rep repo.Repository)

Source from the content-addressed store, hash-verified

600// SetRepository sets the repository (nil is allowed and indicates server that is not
601// connected to the repository).
602func (s *Server) SetRepository(ctx context.Context, rep repo.Repository) error {
603 s.serverMutex.Lock()
604 defer s.serverMutex.Unlock()
605
606 if s.rep == rep {
607 // nothing to do
608 return nil
609 }
610
611 if s.rep != nil {
612 // stop previous scheduler asynchronously to avoid deadlock when
613 // scheduler is inside s.getSchedulerItems which needs a lock, which we're holding right now.
614 go s.sched.Stop()
615
616 s.sched = nil
617
618 s.unmountAllLocked(ctx)
619
620 // close previous source managers
621 userLog(ctx).Debug("stopping all source managers")
622 s.stopAllSourceManagersLocked(ctx)
623 userLog(ctx).Debug("stopped all source managers")
624
625 if err := s.rep.Close(ctx); err != nil {
626 return errors.Wrap(err, "unable to close previous repository")
627 }
628
629 // stop maintenance manager
630 if s.maint != nil {
631 s.maint.stop(ctx)
632 s.maint = nil
633 }
634 }
635
636 s.rep = rep
637 if s.rep == nil {
638 return nil
639 }
640
641 if err := s.syncSourcesLocked(ctx); err != nil {
642 s.stopAllSourceManagersLocked(ctx)
643 s.rep = nil
644
645 return err
646 }
647
648 s.maint = maybeStartMaintenanceManager(ctx, s.rep, s, s.options.MinMaintenanceInterval)
649
650 s.sched = scheduler.Start(context.WithoutCancel(ctx), s.getSchedulerItems, scheduler.Options{
651 TimeNow: clock.Now,
652 Debug: s.options.DebugScheduler,
653 RefreshChannel: s.schedulerRefresh,
654 })
655
656 return nil
657}
658
659// +checklocks:s.serverMutex

Callers 2

InitRepositoryAsyncMethod · 0.95
disconnectMethod · 0.95

Calls 10

unmountAllLockedMethod · 0.95
syncSourcesLockedMethod · 0.95
StartFunction · 0.92
LockMethod · 0.65
UnlockMethod · 0.65
CloseMethod · 0.65
StopMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected