Skip to content

Commit 87d1ccc

Browse files
feat(desktop): atomic write for registry persistence (hoppscotch#5658)
This implements atomic writes for registry.json using a temporary file and renaming to prevent file corruption on Windows 11.
1 parent f88c81f commit 87d1ccc

File tree

7 files changed

+27
-23
lines changed

7 files changed

+27
-23
lines changed

packages/hoppscotch-common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@hoppscotch/httpsnippet": "3.0.9",
4141
"@hoppscotch/js-sandbox": "workspace:^",
4242
"@hoppscotch/kernel": "workspace:^",
43-
"@hoppscotch/plugin-appload": "github:CuriousCorrelation/tauri-plugin-appload#e05861959938b57479a1a81fa796735ebbd08c7c",
43+
"@hoppscotch/plugin-appload": "github:CuriousCorrelation/tauri-plugin-appload#52744a8f35bf81b039410522efd4168bd06d4f35",
4444
"@hoppscotch/ui": "0.2.5",
4545
"@hoppscotch/vue-toasted": "0.1.0",
4646
"@lezer/highlight": "1.2.1",

packages/hoppscotch-desktop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"@fontsource-variable/roboto-mono": "5.2.8",
2525
"@hoppscotch/common": "workspace:^",
2626
"@hoppscotch/kernel": "workspace:^",
27-
"@hoppscotch/plugin-appload": "github:CuriousCorrelation/tauri-plugin-appload#e05861959938b57479a1a81fa796735ebbd08c7c",
27+
"@hoppscotch/plugin-appload": "github:CuriousCorrelation/tauri-plugin-appload#52744a8f35bf81b039410522efd4168bd06d4f35",
2828
"@hoppscotch/ui": "0.2.5",
2929
"@tauri-apps/api": "2.1.1",
3030
"@tauri-apps/plugin-fs": "2.0.2",

packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-appload/src/storage/registry.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use chrono::{DateTime, Utc};
22
use serde::{Deserialize, Serialize};
33
use std::collections::HashMap;
4-
use tokio::fs;
54
use url::Url;
65

76
use super::error::Result;
@@ -30,13 +29,18 @@ impl Registry {
3029
});
3130
}
3231

33-
let content = fs::read_to_string(layout.registry_path()).await?;
32+
let content = tokio::fs::read_to_string(layout.registry_path()).await?;
3433
Ok(serde_json::from_str(&content)?)
3534
}
3635

3736
pub async fn save(&self, layout: &StorageLayout) -> Result<()> {
3837
let content = serde_json::to_string_pretty(self)?;
39-
fs::write(layout.registry_path(), content).await?;
38+
let path = layout.registry_path();
39+
let temp_path = path.with_extension("json.tmp");
40+
41+
tokio::fs::write(&temp_path, &content).await?;
42+
tokio::fs::rename(&temp_path, &path).await?;
43+
4044
Ok(())
4145
}
4246

packages/hoppscotch-desktop/src-tauri/Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hoppscotch-desktop/src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ tauri-plugin-store = "2.4.1"
2929
tauri-plugin-dialog = "2.4.2"
3030
tauri-plugin-fs = "2.4.4"
3131
tauri-plugin-deep-link = "2.4.5"
32-
tauri-plugin-appload = { git = "https://github.com/CuriousCorrelation/tauri-plugin-appload", rev = "e05861959938b57479a1a81fa796735ebbd08c7c" }
32+
tauri-plugin-appload = { git = "https://github.com/CuriousCorrelation/tauri-plugin-appload", rev = "52744a8f35bf81b039410522efd4168bd06d4f35" }
3333
tauri-plugin-relay = { git = "https://github.com/CuriousCorrelation/tauri-plugin-relay", rev = "7cf09c1ad31e228758738c2f4e1c8fe9cc141291" }
3434
axum = "0.8.7"
3535
tower-http = { version = "0.6.6", features = ["cors"] }

packages/hoppscotch-selfhost-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@hoppscotch/common": "workspace:^",
3030
"@hoppscotch/data": "workspace:^",
3131
"@hoppscotch/kernel": "workspace:^",
32-
"@hoppscotch/plugin-appload": "github:CuriousCorrelation/tauri-plugin-appload#e05861959938b57479a1a81fa796735ebbd08c7c",
32+
"@hoppscotch/plugin-appload": "github:CuriousCorrelation/tauri-plugin-appload#52744a8f35bf81b039410522efd4168bd06d4f35",
3333
"@hoppscotch/ui": "0.2.5",
3434
"@import-meta-env/unplugin": "0.6.3",
3535
"@tauri-apps/api": "2.1.1",

pnpm-lock.yaml

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)