Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Migrate from device_id to installation_id key

Joseph T. Lyons81ed86128821
diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs
index 04f468eb2f0..da8ff80c316 100644
--- a/crates/zed/src/main.rs
+++ b/crates/zed/src/main.rs
@@ -327,19 +327,29 @@ async fn authenticate(client: Arc<Client>, cx: &AsyncAppContext) -> Result<()> {
}
async fn installation_id() -> Result<(String, bool)> {
- let legacy_key_name = "device_id";
-
- if let Ok(Some(installation_id)) = KEY_VALUE_STORE.read_kvp(legacy_key_name) {
- Ok((installation_id, true))
- } else {
- let installation_id = Uuid::new_v4().to_string();
+ let legacy_key_name = "device_id".to_string();
+ let key_name = "installation_id".to_string();
+ // Migrate legacy key to new key
+ if let Ok(Some(installation_id)) = KEY_VALUE_STORE.read_kvp(&legacy_key_name) {
KEY_VALUE_STORE
- .write_kvp(legacy_key_name.to_string(), installation_id.clone())
+ .write_kvp(key_name, installation_id.clone())
.await?;
+ KEY_VALUE_STORE.delete_kvp(legacy_key_name).await?;
+ return Ok((installation_id, true));
+ }
- Ok((installation_id, false))
+ if let Ok(Some(installation_id)) = KEY_VALUE_STORE.read_kvp(&key_name) {
+ return Ok((installation_id, true));
}
+
+ let installation_id = Uuid::new_v4().to_string();
+
+ KEY_VALUE_STORE
+ .write_kvp(key_name, installation_id.clone())
+ .await?;
+
+ Ok((installation_id, false))
}
async fn restore_or_create_workspace(app_state: &Arc<AppState>, mut cx: AsyncAppContext) {
diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rs
index a885a81f79e..a24fb7377d9 100644
--- a/crates/zed2/src/main.rs
+++ b/crates/zed2/src/main.rs
@@ -387,19 +387,29 @@ async fn authenticate(client: Arc<Client>, cx: &AsyncAppContext) -> Result<()> {
}
async fn installation_id() -> Result<(String, bool)> {
- let legacy_key_name = "device_id";
-
- if let Ok(Some(installation_id)) = KEY_VALUE_STORE.read_kvp(legacy_key_name) {
- Ok((installation_id, true))
- } else {
- let installation_id = Uuid::new_v4().to_string();
+ let legacy_key_name = "device_id".to_string();
+ let key_name = "installation_id".to_string();
+ // Migrate legacy key to new key
+ if let Ok(Some(installation_id)) = KEY_VALUE_STORE.read_kvp(&legacy_key_name) {
KEY_VALUE_STORE
- .write_kvp(legacy_key_name.to_string(), installation_id.clone())
+ .write_kvp(key_name, installation_id.clone())
.await?;
+ KEY_VALUE_STORE.delete_kvp(legacy_key_name).await?;
+ return Ok((installation_id, true));
+ }
- Ok((installation_id, false))
+ if let Ok(Some(installation_id)) = KEY_VALUE_STORE.read_kvp(&key_name) {
+ return Ok((installation_id, true));
}
+
+ let installation_id = Uuid::new_v4().to_string();
+
+ KEY_VALUE_STORE
+ .write_kvp(key_name, installation_id.clone())
+ .await?;
+
+ Ok((installation_id, false))
}
async fn restore_or_create_workspace(app_state: &Arc<AppState>, mut cx: AsyncAppContext) {