(nextPath string)
| 83 | } |
| 84 | |
| 85 | func (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 | |
| 114 | func (s *Server) Router() http.Handler { |
| 115 | inner := chi.NewRouter() |
no test coverage detected