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

Method open_readonly_mode

atomic-repository/src/repository/mod.rs:873–931  ·  view source on GitHub ↗
(
        path: &Path,
        operation_inspection: bool,
        no_migration: bool,
    )

Source from the content-addressed store, hash-verified

871 }
872
873 fn open_readonly_mode(
874 path: &Path,
875 operation_inspection: bool,
876 no_migration: bool,
877 ) -> Result<Self, RepositoryError> {
878 if let Some((working_root, canonical, view)) = sandbox::detect_sandbox(path) {
879 if no_migration {
880 return Err(RepositoryError::InvalidOperation {
881 message: "non-migrating sandbox inspection is unavailable".to_string(),
882 });
883 }
884 return Self::open_sandbox_readonly(working_root, canonical, &view);
885 }
886 let layout = working_copy::discover_layout(path)?;
887 let root = layout.working_root.clone();
888 let dot_dir = layout.common_dot_dir.clone();
889
890 // Open the pristine database in read-only mode. Identity validation below
891 // performs no repair and reports a typed migration-required error.
892 let database = if no_migration {
893 database::require_current_database(&dot_dir)?
894 } else {
895 ensure_database(&dot_dir)?
896 };
897 let pristine = if no_migration {
898 Pristine::open_readonly_without_recovery(database)
899 } else {
900 Pristine::open_readonly(database)
901 };
902 let pristine = Arc::new(pristine.map_err(RepositoryError::from)?);
903 let (working_copy_id, current_view) =
904 working_copy::load_registered_identity(&pristine, &layout)?;
905
906 // Open the change store without creating missing paths.
907 let change_store =
908 ChangeStore::open_existing(dot_dir.join("changes"), DEFAULT_CACHE_CAPACITY)
909 .map_err(|e| RepositoryError::Database(e.to_string()))?;
910
911 let repository = Self {
912 root,
913 dot_dir,
914 current_view,
915 pristine,
916 change_store,
917 is_sandbox: false,
918 semantic_closure_memo: Default::default(),
919 };
920 if !operation_inspection
921 && (repository.has_pending_deferred_tree_alignment()
922 || repository.working_copy_operation_requires_recovery(working_copy_id)?
923 || repository.repository_operation_requires_recovery()?)
924 {
925 return Err(RepositoryError::InvalidOperation {
926 message: "repository operation is still completing; retry with a writable repository open"
927 .to_string(),
928 });
929 }
930 Ok(repository)

Callers

nothing calls this directly

Calls 9

detect_sandboxFunction · 0.85
discover_layoutFunction · 0.85
require_current_databaseFunction · 0.85
ensure_databaseFunction · 0.85
load_registered_identityFunction · 0.85
cloneMethod · 0.45

Tested by

no test coverage detected