fix(tauri): add_workspace must initialise the target folder
The frontend currently calls init_workspace before add_workspace, but the Tauri command itself is trivially breakable by any caller that skips the pre-step or a future frontend refactor: add_workspace would save the workspace entry pointing at a non-existent directory, and every subsequent command would then fail with 'Path does not exist' via TaskRepository::new. Call TaskRepository::init inside the command so it is self-contained and idempotent.
This commit is contained in:
parent
604a6058b8
commit
df66e7bc98
|
|
@ -179,6 +179,13 @@ fn add_workspace(
|
|||
state: State<'_, Mutex<AppState>>,
|
||||
) -> Result<(), String> {
|
||||
validate_workspace_path(&path)?;
|
||||
// Ensure the path exists and is a valid workspace before persisting the
|
||||
// config. Without this, calling add_workspace directly on a missing
|
||||
// directory would save the workspace but every subsequent ensure_repo
|
||||
// call would fail with "Path does not exist".
|
||||
TaskRepository::init(PathBuf::from(&path))
|
||||
.map(|_| ())
|
||||
.map_err(|e| e.to_string())?;
|
||||
let mut s = lock_state(&state)?;
|
||||
let ws = WorkspaceConfig::new(name, PathBuf::from(&path));
|
||||
let id = s.config.add_workspace(ws);
|
||||
|
|
|
|||
Loading…
Reference in a new issue