Skip to content

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

Description

@ryantaylor

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!

Activity

  1. FabianLars commented on Feb 23, 2024

    @FabianLars
    Member

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

  2. linked a pull request that will close this issuerefactor(store)!: more reworks #1860on Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions