Skip to content

Commit 99cafa6

Browse files
committed
Fix description and create_new logic
1 parent 3288e4b commit 99cafa6

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

plugins/store/guest-js/index.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ export type StoreOptions = {
4949
*
5050
* @param path Path to save the store in `app_data_dir`
5151
* @param options Store configuration options
52-
*
53-
* @throws If a store at that path is already loaded
5452
*/
5553
export async function create(
5654
path: string,
@@ -75,8 +73,6 @@ export async function create(
7573
*
7674
* @param path Path to save the store in `app_data_dir`
7775
* @param options Store configuration options
78-
*
79-
* @throws If a store at that path is already loaded
8076
*/
8177
export async function load(
8278
path: string,
@@ -232,8 +228,6 @@ export class Store extends Resource implements IStore {
232228
*
233229
* @param path Path to save the store in `app_data_dir`
234230
* @param options Store configuration options
235-
*
236-
* @throws If a store at that path is already loaded
237231
*/
238232
static async create(path: string, options?: StoreOptions): Promise<Store> {
239233
const rid = await invoke<number>('plugin:store|create_store', {
@@ -259,8 +253,6 @@ export class Store extends Resource implements IStore {
259253
*
260254
* @param path Path to save the store in `app_data_dir`
261255
* @param options Store configuration options
262-
*
263-
* @throws If a store at that path is already loaded
264256
*/
265257
static async load(path: string, options?: StoreOptions): Promise<Store> {
266258
const rid = await invoke<number>('plugin:store|load', {

plugins/store/permissions/autogenerated/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ All operations are enabled by default.
2323
- `allow-values`
2424
- `allow-entries`
2525
- `allow-length`
26-
- `allow-load`
26+
- `allow-reload`
2727
- `allow-save`
2828

2929
## Permission Table

plugins/store/src/error.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// SPDX-License-Identifier: MIT
44

55
use serde::{Serialize, Serializer};
6-
use std::path::PathBuf;
76

87
pub type Result<T> = std::result::Result<T, Error>;
98

@@ -21,9 +20,9 @@ pub enum Error {
2120
/// IO error.
2221
#[error(transparent)]
2322
Io(#[from] std::io::Error),
24-
/// Store already exists
25-
#[error("Store at \"{0}\" already exists")]
26-
AlreadyExists(PathBuf),
23+
// /// Store already exists
24+
// #[error("Store at \"{0}\" already exists")]
25+
// AlreadyExists(PathBuf),
2726
/// Serialize function not found
2827
#[error("Serialize Function \"{0}\" not found")]
2928
SerializeFunctionNotFound(String),

plugins/store/src/store.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<R: Runtime> StoreBuilder<R> {
172172
self
173173
}
174174

175-
/// Force create a new store even if it already exists.
175+
/// Force create a new store with default values even if it already exists.
176176
pub fn create_new(mut self) -> Self {
177177
self.create_new = true;
178178
self
@@ -181,14 +181,23 @@ impl<R: Runtime> StoreBuilder<R> {
181181
pub(crate) fn build_inner(mut self) -> crate::Result<(Arc<Store<R>>, ResourceId)> {
182182
let stores = self.app.state::<StoreState>().stores.clone();
183183
let mut stores = stores.lock().unwrap();
184-
if let Some(rid) = stores.get(&self.path) {
185-
return Ok((self.app.resources_table().get(*rid).unwrap(), *rid));
186-
}
187184

188-
if stores.contains_key(&self.path) {
189-
return Err(crate::Error::AlreadyExists(self.path));
185+
self.path = resolve_store_path(&self.app, self.path)?;
186+
187+
if self.create_new {
188+
if let Some(rid) = stores.remove(&self.path) {
189+
let _ = self.app.resources_table().take::<Store<R>>(rid);
190+
}
191+
} else {
192+
if let Some(rid) = stores.get(&self.path) {
193+
return Ok((self.app.resources_table().get(*rid).unwrap(), *rid));
194+
}
190195
}
191196

197+
// if stores.contains_key(&self.path) {
198+
// return Err(crate::Error::AlreadyExists(self.path));
199+
// }
200+
192201
let mut store_inner = StoreInner::new(
193202
self.app.clone(),
194203
self.path.clone(),

0 commit comments

Comments
 (0)