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

Function compact_file

libatomic/src/daemon/services_maintenance/compact.rs:163–187  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

161}
162
163fn compact_file(path: &Path) -> anyhow::Result<CompactDatabaseResponse> {
164 let readonly = redb::Builder::new().open_read_only(path)?;
165 let txn = readonly.begin_read()?;
166 atomic_core::pristine::schema::check_schema_version(&txn)?;
167 atomic_core::pristine::schema::check_required_capabilities(&txn)?;
168 drop(txn);
169 drop(readonly);
170 let mut database = redb::Builder::new().open(path)?;
171 let txn = database.begin_read()?;
172 atomic_core::pristine::schema::check_schema_version(&txn)?;
173 atomic_core::pristine::schema::check_required_capabilities(&txn)?;
174 drop(txn);
175 let before_bytes = std::fs::metadata(path)?.len();
176 database.compact()?;
177 // Closing persists allocator metadata; include that in the final size.
178 drop(database);
179 let after_bytes = std::fs::metadata(path)?.len();
180 Ok(CompactDatabaseResponse {
181 database: path.to_string_lossy().into_owned(),
182 before_bytes,
183 after_bytes,
184 reclaimed_bytes: before_bytes.saturating_sub(after_bytes),
185 meta: None,
186 })
187}
188
189fn with_request_id(status: Status, request_id: &str) -> Status {
190 let code = match status.code() {

Calls 5

check_schema_versionFunction · 0.85
begin_readMethod · 0.80
openMethod · 0.45
lenMethod · 0.45