feat: implement path normalization across commands
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::{DesktopRuntime, SettingsStore};
|
||||
use crate::path_utils::expand_tilde_path;
|
||||
use serde::Serialize;
|
||||
use std::{
|
||||
collections::{HashSet, VecDeque},
|
||||
@@ -346,7 +347,7 @@ async fn resolve_sandboxed_path(
|
||||
.filter(|value| !value.is_empty());
|
||||
|
||||
let candidate_path = match (candidate_input, workspace_root) {
|
||||
(Some(value), _) => PathBuf::from(value),
|
||||
(Some(value), _) => expand_tilde_path(value),
|
||||
(None, Some(root)) => root.clone(),
|
||||
(None, None) => default_home_directory(),
|
||||
};
|
||||
@@ -376,7 +377,7 @@ async fn resolve_creatable_path(
|
||||
path: &str,
|
||||
workspace_root: Option<&PathBuf>,
|
||||
) -> Result<PathBuf, FsCommandError> {
|
||||
let candidate = PathBuf::from(path);
|
||||
let candidate = expand_tilde_path(path);
|
||||
if candidate.as_os_str().is_empty() {
|
||||
return Err(FsCommandError::Other("Path is required".to_string()));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::{DesktopRuntime, SettingsStore};
|
||||
use crate::path_utils::expand_tilde_path;
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use log::{error, info, warn};
|
||||
use regex::Regex;
|
||||
@@ -357,7 +358,7 @@ fn append_git_option_map(args: &mut Vec<String>, map: &serde_json::Map<String, V
|
||||
// Removed unused resolve_workspace_root function
|
||||
|
||||
async fn validate_git_path(path: &str, _settings: &SettingsStore) -> Result<PathBuf> {
|
||||
let path_buf = PathBuf::from(path);
|
||||
let path_buf = expand_tilde_path(path);
|
||||
if !path_buf.exists() {
|
||||
return Err(anyhow!("Directory does not exist: {}", path));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use tauri::AppHandle;
|
||||
use tauri::State;
|
||||
|
||||
use crate::DesktopRuntime;
|
||||
use crate::path_utils::expand_tilde_path;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -34,10 +35,12 @@ pub async fn process_directory_selection(
|
||||
path: String,
|
||||
state: State<'_, DesktopRuntime>,
|
||||
) -> Result<DirectoryPermissionResult, String> {
|
||||
use std::path::PathBuf;
|
||||
|
||||
// Validate directory exists
|
||||
let path_buf = PathBuf::from(&path);
|
||||
let mut path_buf = expand_tilde_path(&path);
|
||||
if let Ok(canonicalized) = std::fs::canonicalize(&path_buf) {
|
||||
path_buf = canonicalized;
|
||||
}
|
||||
let normalized_path = path_buf.to_string_lossy().to_string();
|
||||
if !path_buf.exists() {
|
||||
return Ok(DirectoryPermissionResult {
|
||||
success: false,
|
||||
@@ -64,7 +67,7 @@ pub async fn process_directory_selection(
|
||||
if let Some(obj) = settings.as_object_mut() {
|
||||
obj.insert(
|
||||
"lastDirectory".to_string(),
|
||||
serde_json::Value::String(path.clone()),
|
||||
serde_json::Value::String(normalized_path.clone()),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -76,12 +79,12 @@ pub async fn process_directory_selection(
|
||||
|
||||
info!(
|
||||
"[permissions] Updated settings with lastDirectory: {}",
|
||||
path
|
||||
normalized_path
|
||||
);
|
||||
|
||||
Ok(DirectoryPermissionResult {
|
||||
success: true,
|
||||
path: Some(path),
|
||||
path: Some(normalized_path),
|
||||
error: None,
|
||||
})
|
||||
}
|
||||
@@ -110,7 +113,11 @@ pub async fn request_directory_access(
|
||||
) -> Result<DirectoryPermissionResult, String> {
|
||||
let path = request.path;
|
||||
|
||||
let path_buf = std::path::PathBuf::from(&path);
|
||||
let mut path_buf = expand_tilde_path(&path);
|
||||
if let Ok(canonicalized) = std::fs::canonicalize(&path_buf) {
|
||||
path_buf = canonicalized;
|
||||
}
|
||||
let normalized_path = path_buf.to_string_lossy().to_string();
|
||||
if !path_buf.exists() {
|
||||
return Ok(DirectoryPermissionResult {
|
||||
success: false,
|
||||
@@ -131,7 +138,7 @@ pub async fn request_directory_access(
|
||||
match std::fs::read_dir(&path_buf) {
|
||||
Ok(_) => Ok(DirectoryPermissionResult {
|
||||
success: true,
|
||||
path: Some(path),
|
||||
path: Some(normalized_path),
|
||||
error: None,
|
||||
}),
|
||||
Err(e) => Ok(DirectoryPermissionResult {
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::collections::HashSet;
|
||||
use tauri::State;
|
||||
|
||||
use crate::DesktopRuntime;
|
||||
use crate::path_utils::expand_tilde_path;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -105,12 +106,14 @@ fn sanitize_settings_update(payload: &Value) -> Value {
|
||||
}
|
||||
if let Some(Value::String(s)) = obj.get("lastDirectory") {
|
||||
if !s.is_empty() {
|
||||
result_obj.insert("lastDirectory".to_string(), json!(s));
|
||||
let expanded = expand_tilde_path(s).to_string_lossy().to_string();
|
||||
result_obj.insert("lastDirectory".to_string(), json!(expanded));
|
||||
}
|
||||
}
|
||||
if let Some(Value::String(s)) = obj.get("homeDirectory") {
|
||||
if !s.is_empty() {
|
||||
result_obj.insert("homeDirectory".to_string(), json!(s));
|
||||
let expanded = expand_tilde_path(s).to_string_lossy().to_string();
|
||||
result_obj.insert("homeDirectory".to_string(), json!(expanded));
|
||||
}
|
||||
}
|
||||
if let Some(Value::String(s)) = obj.get("uiFont") {
|
||||
|
||||
Reference in New Issue
Block a user