remove the unread forge-core-token at startup
This commit is contained in:
parent
0f4566c8d3
commit
d893097ffe
2 changed files with 31 additions and 3 deletions
|
|
@ -69,6 +69,11 @@ pub async fn run() -> Result<()> {
|
|||
migrate_harness_files(name);
|
||||
}
|
||||
|
||||
match remove_core_token(&crate::paths::state_root()) {
|
||||
Ok(true) => tracing::info!("migration: removed the unread forge-core-token"),
|
||||
Ok(false) => {}
|
||||
Err(e) => tracing::warn!(error = ?e, "migration: removing the forge-core-token failed"),
|
||||
}
|
||||
match remove_legacy_meta_git(&crate::paths::meta_root()) {
|
||||
Ok(true) => tracing::info!("migration: removed the legacy meta repo's .git"),
|
||||
Ok(false) => {}
|
||||
|
|
@ -174,6 +179,17 @@ fn remove_legacy_meta_git(meta: &Path) -> Result<bool> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Remove the forge admin token file an earlier hive left in `state`; nothing
|
||||
/// reads it. `true` when it was there.
|
||||
fn remove_core_token(state: &Path) -> Result<bool> {
|
||||
let file = state.join("forge-core-token");
|
||||
match std::fs::remove_file(&file) {
|
||||
Ok(()) => Ok(true),
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(false),
|
||||
Err(e) => Err(e).with_context(|| format!("removing {}", file.display())),
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove the `meta` remote from the proposed repo at `dir`. `true` when it
|
||||
/// was there; a missing remote, or a `dir` that is no repo, is `false`.
|
||||
async fn remove_meta_remote(dir: &Path) -> Result<bool> {
|
||||
|
|
@ -342,6 +358,18 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn core_token_goes_once_and_its_neighbours_stay() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
std::fs::write(dir.path().join("forge-core-token"), "x").expect("write token");
|
||||
std::fs::write(dir.path().join("forge-other"), "x").expect("write neighbour");
|
||||
|
||||
assert!(remove_core_token(dir.path()).expect("first"));
|
||||
assert!(!dir.path().join("forge-core-token").exists());
|
||||
assert!(dir.path().join("forge-other").exists(), "neighbour stays");
|
||||
assert!(!remove_core_token(dir.path()).expect("second"), "no-op");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_dir_that_is_no_repo_has_no_meta_remote() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
|
|
|
|||
Loading…
Reference in a new issue