From 21117da114ea18288701f966a98625a3d63e377a Mon Sep 17 00:00:00 2001 From: Bruno Charest Date: Thu, 4 Jun 2026 17:10:40 -0400 Subject: [PATCH] fix: backup listing uses same vault for read/write + global close handler - _get_backup_dir: now resolves relative path using the SPECIFIC vault's directory (matching _backup_file exactly), not the first vault in index - Removed _get_backup_root (unused after refactor) - backups.js: global document click handler for #backup-close (same pattern as Graph View's initGraphView) --- backend/main.py | 34 ++++++++++------------------------ frontend/js/backups.js | 6 ++++++ 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/backend/main.py b/backend/main.py index f91485c..4709ca3 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1933,31 +1933,17 @@ async def api_file_move( # Backup & Diff endpoints # --------------------------------------------------------------------------- -def _get_backup_root() -> Path: - """Return the backup root directory as configured. - - If the configured path is relative, it is resolved relative to the - first vault's parent directory for consistency with _backup_file. - """ - root = Path(os.environ.get("OBSIGATE_BACKUP_DIR", ".obsigate-backup")) - if not root.is_absolute(): - # Resolve relative to vault root (inside vault, always writable) - try: - from backend.indexer import get_vault_data as _get_vd - vaults = index - if vaults: - first_name = next(iter(vaults.keys())) - vd = _get_vd(first_name) - if vd: - root = Path(vd["path"]) / root - except Exception: - pass # fall back to relative - return root - - def _get_backup_dir(vault_name: str, relative_path: str) -> Path: - """Return the directory where backups for a specific file are stored.""" - backup_root = _get_backup_root() + """Return the directory where backups for a specific file are stored. + + Resolves relative backup paths against the SPECIFIC vault's directory, + matching _backup_file's resolution logic exactly. + """ + backup_root = Path(os.environ.get("OBSIGATE_BACKUP_DIR", ".obsigate-backup")) + if not backup_root.is_absolute(): + vault_data = get_vault_data(vault_name) + if vault_data: + backup_root = Path(vault_data["path"]) / backup_root return backup_root / vault_name / Path(relative_path).parent diff --git a/frontend/js/backups.js b/frontend/js/backups.js index cfd92c9..3f3be15 100644 --- a/frontend/js/backups.js +++ b/frontend/js/backups.js @@ -14,6 +14,12 @@ import { showToast } from './ui.js'; import { refreshSidebarTreePreservingState } from './sidebar.js'; import { safeCreateIcons } from './utils.js'; +// Global handler: same pattern as Graph View's initGraphView() +document.addEventListener('click', function(e) { + const btn = e.target.closest('#backup-close'); + if (btn && state.overlay) close(); +}); + // --------------------------------------------------------------------------- // State // ---------------------------------------------------------------------------