Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[store] Absolute vs. relative paths to the same store file are cached separately #984

Closed
ryantaylor opened this issue Feb 23, 2024 · 1 comment · Fixed by #1860 or #1909
Closed
Labels
enhancement New feature or request plugin: store

Comments

@ryantaylor
Copy link

ryantaylor commented Feb 23, 2024

Came across an interesting edge case today in the store plugin. If I create a store in JS like this:

const store = new Store(appDataDir() + "config.file")

and I try to access it from Rust like this:

let stores = app.state::<StoreCollection<Wry>>();
let path = PathBuf::from("config.file");

with_store(app_handle, stores, path, |store| store.insert("a".to_string(), json!("b")))

these will load from and save to the same file on the filesystem (thanks to https://github.com/tauri-apps/plugins-workspace/blob/v1/plugins/store/src/store.rs#L179), but they'll be cached separately because with_store just uses the key you give it (which in this case is an absolute path in JS and a relative path in Rust) - the line in question is here: https://github.com/tauri-apps/plugins-workspace/blob/v1/plugins/store/src/lib.rs#L57.

Since these two paths point to the same store file and load from/save to the same file, it feels to me like with_store should key on the absolute path constructed by load and save instead of just whatever the caller gives it.

Happy to throw together a quick PR in this direction if we think it makes sense!

@FabianLars
Copy link
Member

i agree, i think it makes sense to resolve paths first, PR would be much appreciated :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request plugin: store
Projects
None yet
2 participants