MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / open_once

Method open_once

atomic-repository/src/repository/mod.rs:590–667  ·  view source on GitHub ↗
(path: &Path, budget: ReconcileEffectBudget)

Source from the content-addressed store, hash-verified

588 }
589
590 fn open_once(path: &Path, budget: ReconcileEffectBudget) -> Result<Self, RepositoryError> {
591 if let Some((working_root, canonical, view)) = sandbox::detect_sandbox(path) {
592 if budget.is_metadata_only() {
593 database::require_current_database(&Self::canonical_dot_dir(&canonical)?)?;
594 }
595 // CB-13D ::24 R1: the sandbox open passes the SAME budget gate
596 // as the ordinary open — it must not return before the
597 // recovery fence (a metadata-only sandbox open refuses unsafe
598 // pending recovery instead of replaying it).
599 let mut sandbox = Self::open_sandbox(working_root, canonical, &view)?;
600 let working_copy = sandbox.require_working_copy_id()?;
601 sandbox.fence_recovery_for_budget(working_copy, budget)?;
602 return Ok(sandbox);
603 }
604
605 let mut layout = working_copy::discover_layout(path)?;
606 let root = layout.working_root.clone();
607 let dot_dir = layout.common_dot_dir.clone();
608
609 // PATH_CLAIMS migration still needs a view name. Prefer an existing
610 // working-copy record; consult legacy compatibility files only when no
611 // record owns this canonical location yet.
612 let legacy_view =
613 Self::read_legacy_current_view(&layout.working_copy_dot_dir, &layout.common_dot_dir)?;
614
615 // Legacy consolidation validates capabilities before moving files;
616 // Pristine::open repeats the check before additive table initialization.
617 // Pointer creation, path-claim migration, and recovery remain after
618 // capability validation.
619 let pristine_path = if budget.is_metadata_only() {
620 database::require_current_database(&dot_dir)?
621 } else {
622 ensure_database(&dot_dir)?
623 };
624 let pristine = Pristine::open(&pristine_path).map_err(RepositoryError::from)?;
625
626 working_copy::ensure_repository_pointer(&layout)?;
627 layout.pointer_needs_write = false;
628 let change_store = ChangeStore::new(dot_dir.join("changes"), DEFAULT_CACHE_CAPACITY)
629 .map_err(|e| RepositoryError::Database(e.to_string()))?;
630 let migration_view =
631 working_copy::registered_view_name(&pristine, &layout)?.unwrap_or(legacy_view);
632 let pristine = migration::migrate_path_claims_if_required(
633 &pristine_path,
634 pristine,
635 &change_store,
636 &migration_view,
637 )?;
638 let (working_copy_id, current_view) =
639 working_copy::migrate_identity(&pristine, &layout, &migration_view)?;
640 let pristine = Arc::new(pristine);
641
642 let mut repository = Self {
643 root,
644 dot_dir,
645 current_view,
646 pristine,
647 change_store,

Callers

nothing calls this directly

Calls 15

detect_sandboxFunction · 0.85
require_current_databaseFunction · 0.85
discover_layoutFunction · 0.85
ensure_databaseFunction · 0.85
registered_view_nameFunction · 0.85
migrate_identityFunction · 0.85
load_registered_identityFunction · 0.85

Tested by

no test coverage detected