MCPcopy Index your code
hub / github.com/ZenNotes/zennotes / switchVaultRoot

Method switchVaultRoot

apps/server/internal/httpserver/server.go:85–112  ·  view source on GitHub ↗
(nextPath string)

Source from the content-addressed store, hash-verified

83}
84
85func (s *Server) switchVaultRoot(nextPath string) (*vault.Vault, error) {
86 cfg := s.currentConfig()
87 nextVault, err := vault.New(nextPath, vault.Options{
88 FileMode: cfg.VaultFileMode,
89 DirMode: cfg.VaultDirMode,
90 MaxAssetBytes: cfg.MaxAssetBytes,
91 })
92 if err != nil {
93 return nil, err
94 }
95 // Non-fatal: a vault switch must not fail just because inotify is
96 // unavailable; fall back to a no-op watcher in that case. (#179)
97 nextWatcher := watcher.StartOrDisabled(nextVault.Root(), cfg.DisableWatcher)
98
99 s.mu.Lock()
100 prevWatcher := s.Watcher
101 s.Vault = nextVault
102 s.Watcher = nextWatcher
103 s.Config.VaultPath = nextVault.Root()
104 cfg = s.Config
105 s.mu.Unlock()
106
107 if prevWatcher != nil {
108 prevWatcher.Close()
109 }
110 _ = config.SaveHost(cfg)
111 return nextVault, nil
112}
113
114func (s *Server) Router() http.Handler {
115 inner := chi.NewRouter()

Callers 1

selectVaultMethod · 0.95

Calls 3

currentConfigMethod · 0.95
RootMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected