YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
refactor: delete legacy OAuth files after migration to SecretStore
Louis Beaumont385131236fbf
diff --git a/crates/screenpipe-engine/src/secret_oauth.rs b/crates/screenpipe-engine/src/secret_oauth.rsindex f748a3ad6..62ff4cc0a 100644--- a/crates/screenpipe-engine/src/secret_oauth.rs+++ b/crates/screenpipe-engine/src/secret_oauth.rs@@ -37,7 +37,7 @@ pub async fn load_oauth_from_store_or_file(/// Save an OAuth token JSON blob into the SecretStore AND the legacy file/// (dual-write for backward compatibility during migration).-pub async fn save_oauth_to_store_and_file(+pub async fn save_oauth_to_store(store: &SecretStore,integration_id: &str,instance: Option<&str>,@@ -48,23 +48,7 @@ pub async fn save_oauth_to_store_and_file(None => format!("oauth:{}", integration_id),};- // Write to SecretStore- store.set_json(&key, value).await?;-- // Also write to legacy file for backward compatibility- let path = screenpipe_connect::oauth::oauth_token_path_instance(integration_id, instance);- let json_bytes = serde_json::to_vec_pretty(value)?;- std::fs::write(&path, &json_bytes)?;-- // Fix permissions on the file we just wrote- #[cfg(unix)]- {- use std::os::unix::fs::PermissionsExt;- let perms = std::fs::Permissions::from_mode(0o600);- let _ = std::fs::set_permissions(&path, perms);- }-- Ok(())+ store.set_json(&key, value).await}#[cfg(test)]diff --git a/crates/screenpipe-secrets/src/migration.rs b/crates/screenpipe-secrets/src/migration.rsindex 9f94956df..757ded96b 100644--- a/crates/screenpipe-secrets/src/migration.rs+++ b/crates/screenpipe-secrets/src/migration.rs@@ -71,10 +71,14 @@ pub async fn migrate_legacy_secrets(if let Err(e) = store.set(&store_key, &contents).await {report.errors.push(format!("{}: {}", filename, e));} else {+ // Delete the legacy file — secrets live in SecretStore now+ if let Err(e) = std::fs::remove_file(&path) {+ warn!("migrated {} but failed to delete: {}", filename, e);+ }report.migrated.push(format!("{} -> {}", filename, store_key));- info!("migrated {} -> {}", filename, store_key);+ info!("migrated {} -> {} (file deleted)", filename, store_key);}}Err(e) => {@@ -344,14 +348,19 @@ mod tests {let store = make_store().await;- // First migration+ // First migration — file migrated and deletedlet report1 = migrate_legacy_secrets(&store, dir_path).await.unwrap();assert_eq!(report1.migrated.len(), 1);+ assert!(!dir_path.join("gmail-oauth.json").exists(), "file should be deleted after migration");- // Second migration should skip+ // Second migration — file gone, nothing to migrate or skiplet report2 = migrate_legacy_secrets(&store, dir_path).await.unwrap();assert_eq!(report2.migrated.len(), 0);- assert_eq!(report2.skipped.len(), 1);+ assert_eq!(report2.skipped.len(), 0);++ // Value still in store+ let val = store.get("oauth:gmail").await.unwrap();+ assert!(val.is_some(), "secret should still be in store");}#[test]