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

Function ensure_database

atomic-repository/src/repository/database.rs:81–104  ·  view source on GitHub ↗

Return `.atomic/atomic.redb`, merging a legacy layout into it first. # Errors - `DatabaseBusy` while another process holds a database file; retry. - `LegacyChangeStoreBusy` when an owner from an older atomic holds `changes.redb`. - `InvalidRepository` when both layouts exist and no interrupted merge explains it.

(dot_dir: &Path)

Source from the content-addressed store, hash-verified

79/// - `InvalidRepository` when both layouts exist and no interrupted merge
80/// explains it.
81pub fn ensure_database(dot_dir: &Path) -> Result<PathBuf, RepositoryError> {
82 let database = dot_dir.join(DATABASE_FILE);
83 if !dot_dir.join(LEGACY_PRISTINE_FILE).is_file() {
84 return existing(database, dot_dir);
85 }
86
87 // Lock the legacy graph before deciding anything, so concurrent opens of
88 // one repository queue behind a single merge instead of racing it.
89 let mut legacy = LegacyDatabases::new();
90 if let Err(error) = legacy.add(&dot_dir.join(LEGACY_PRISTINE_FILE)) {
91 // Another open finished the merge and moved the file away meanwhile.
92 if is_not_found(&error) {
93 return existing(database, dot_dir);
94 }
95 return Err(error.into());
96 }
97 add_change_store(&mut legacy, dot_dir)?;
98 if database.is_file() {
99 finish_retiring_legacy(dot_dir, &legacy)?;
100 } else {
101 merge_legacy(dot_dir, &legacy)?;
102 }
103 Ok(database)
104}
105
106fn existing(database: PathBuf, dot_dir: &Path) -> Result<PathBuf, RepositoryError> {
107 if database.is_file() {

Callers 7

open_onceMethod · 0.85
open_existing_onceMethod · 0.85
open_readonly_modeMethod · 0.85
change_storeMethod · 0.85
openMethod · 0.85

Calls 7

existingFunction · 0.85
is_not_foundFunction · 0.85
add_change_storeFunction · 0.85
finish_retiring_legacyFunction · 0.85
merge_legacyFunction · 0.85
is_fileMethod · 0.45
addMethod · 0.45