Skip to content

Commit d622fd1

Browse files
fix(migrate): report invalid reconstruction metadata
1 parent 4de38a9 commit d622fd1

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

src/migrate/registry.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,8 +1056,42 @@ fn reconstruct_graph_scopes(
10561056
let Some(branch_dir) = branch_meta_path.parent() else {
10571057
return (None, Vec::new(), Vec::new());
10581058
};
1059-
let Some(meta) = branch_meta::load_branch_meta(branch_dir) else {
1060-
return (None, Vec::new(), Vec::new());
1059+
let invalid = |message| (None, Vec::new(), vec![message]);
1060+
let metadata = match fs::symlink_metadata(branch_meta_path) {
1061+
Ok(metadata) => metadata,
1062+
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
1063+
return (None, Vec::new(), Vec::new());
1064+
}
1065+
Err(error) => {
1066+
return invalid(format!(
1067+
"could not inspect branch metadata '{}': {error}",
1068+
branch_meta_path.display()
1069+
));
1070+
}
1071+
};
1072+
if !metadata.file_type().is_file() {
1073+
return invalid(format!(
1074+
"branch metadata '{}' is not a regular file",
1075+
branch_meta_path.display()
1076+
));
1077+
}
1078+
let content = match fs::read_to_string(branch_meta_path) {
1079+
Ok(content) => content,
1080+
Err(error) => {
1081+
return invalid(format!(
1082+
"could not read branch metadata '{}': {error}",
1083+
branch_meta_path.display()
1084+
));
1085+
}
1086+
};
1087+
let meta = match branch_meta::parse(&content) {
1088+
Ok(meta) => meta,
1089+
Err(error) => {
1090+
return invalid(format!(
1091+
"branch metadata '{}' is invalid: {error}",
1092+
branch_meta_path.display()
1093+
));
1094+
}
10611095
};
10621096
let mut scopes = Vec::new();
10631097
let mut issues = Vec::new();

tests/storage_suite/profile_storage_migration_test.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,9 @@ fn unsafe_branch_database_path_blocks_reconstruction() {
351351
report
352352
.issues
353353
.iter()
354-
.any(|issue| issue.contains("unsafe database path"))
354+
.any(|issue| issue.contains("must reference canonical main database")),
355+
"unexpected reconstruction issues: {:?}",
356+
report.issues
355357
);
356358
}
357359

0 commit comments

Comments
 (0)