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

Function collect

atomic-cli/src/commands/diagnostics/metrics.rs:186–305  ·  view source on GitHub ↗
(workspace: &Result<Option<PathBuf>, SourceError>)

Source from the content-addressed store, hash-verified

184}
185
186pub(crate) fn collect(workspace: &Result<Option<PathBuf>, SourceError>) -> RepositoryMetrics {
187 let root = match workspace {
188 Ok(Some(root)) => root,
189 Ok(None) => {
190 return RepositoryMetrics::NotApplicable {
191 reason: "not inside an Atomic workspace",
192 }
193 }
194 Err(_) => {
195 return RepositoryMetrics::Unavailable {
196 reason: "workspace cannot be determined",
197 database_bytes: None,
198 }
199 }
200 };
201 let dot = match atomic_repository::Repository::canonical_dot_dir(root) {
202 Ok(dot) => dot,
203 Err(_) => {
204 return RepositoryMetrics::Unavailable {
205 reason: "repository database location unavailable",
206 database_bytes: None,
207 }
208 }
209 };
210 let path = dot.join(atomic_repository::DATABASE_FILE);
211 let size = std::fs::metadata(&path).ok().map(|m| m.len());
212 // A legacy layout (including an interrupted merge) cannot be interpreted
213 // as the authoritative current database without the migration protocol.
214 match std::fs::metadata(dot.join(atomic_repository::LEGACY_PRISTINE_FILE)) {
215 Ok(_) => {
216 return RepositoryMetrics::Unavailable {
217 reason: "legacy repository layout requires migration",
218 database_bytes: size,
219 };
220 }
221 Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
222 Err(_) => {
223 return RepositoryMetrics::Unavailable {
224 reason: "repository layout cannot be verified",
225 database_bytes: size,
226 };
227 }
228 }
229 let database = match redb::ReadOnlyDatabase::open(&path) {
230 Ok(database) => database,
231 Err(_) => {
232 return RepositoryMetrics::Unavailable {
233 reason: "repository database cannot be read or is in use",
234 database_bytes: size,
235 }
236 }
237 };
238 let txn = match database.begin_read() {
239 Ok(txn) => txn,
240 Err(_) => {
241 return RepositoryMetrics::Unavailable {
242 reason: "repository database cannot be read",
243 database_bytes: size,

Callers 1

runMethod · 0.70

Calls 12

openFunction · 0.85
statisticsFunction · 0.85
intentsFunction · 0.85
build_versionFunction · 0.85
begin_readMethod · 0.80
valueMethod · 0.80
current_viewFunction · 0.70
unavailableFunction · 0.50
okMethod · 0.45
lenMethod · 0.45
kindMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected