fix: model download - windows path issue
This commit is contained in:
parent
2f02a228cc
commit
a8ed759a06
@ -4,8 +4,6 @@ use crate::core::utils::normalize_path;
|
|||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
|
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::Component;
|
|
||||||
use std::path::Prefix;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tauri::{Emitter, State};
|
use tauri::{Emitter, State};
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
@ -166,25 +164,6 @@ async fn _download_files_internal(
|
|||||||
let save_path = jan_data_folder.join(&item.save_path);
|
let save_path = jan_data_folder.join(&item.save_path);
|
||||||
let save_path = normalize_path(&save_path);
|
let save_path = normalize_path(&save_path);
|
||||||
|
|
||||||
// enforce scope
|
|
||||||
// Remove \\?\ prefix on Windows for correct path comparison
|
|
||||||
#[cfg(windows)]
|
|
||||||
let save_path = {
|
|
||||||
let mut comps = save_path.components();
|
|
||||||
if let Some(Component::Prefix(prefix_comp)) = comps.next() {
|
|
||||||
if let Prefix::Verbatim(_) = prefix_comp.kind() {
|
|
||||||
// Skip the \\?\ prefix
|
|
||||||
comps.as_path().to_path_buf()
|
|
||||||
} else {
|
|
||||||
save_path.clone()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
save_path.clone()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
let save_path = save_path.clone();
|
|
||||||
|
|
||||||
if !save_path.starts_with(&jan_data_folder) {
|
if !save_path.starts_with(&jan_data_folder) {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"Path {} is outside of Jan data folder {}",
|
"Path {} is outside of Jan data folder {}",
|
||||||
|
|||||||
@ -6,6 +6,7 @@ use std::path::{Component, Path, PathBuf};
|
|||||||
use tauri::Runtime;
|
use tauri::Runtime;
|
||||||
|
|
||||||
use super::cmd::get_jan_data_folder_path;
|
use super::cmd::get_jan_data_folder_path;
|
||||||
|
use std::path::Prefix;
|
||||||
|
|
||||||
pub const THREADS_DIR: &str = "threads";
|
pub const THREADS_DIR: &str = "threads";
|
||||||
pub const THREADS_FILE: &str = "thread.json";
|
pub const THREADS_FILE: &str = "thread.json";
|
||||||
@ -53,9 +54,32 @@ pub fn ensure_thread_dir_exists<R: Runtime>(
|
|||||||
// https://github.com/rust-lang/cargo/blob/rust-1.67.0/crates/cargo-util/src/paths.rs#L82-L107
|
// https://github.com/rust-lang/cargo/blob/rust-1.67.0/crates/cargo-util/src/paths.rs#L82-L107
|
||||||
pub fn normalize_path(path: &Path) -> PathBuf {
|
pub fn normalize_path(path: &Path) -> PathBuf {
|
||||||
let mut components = path.components().peekable();
|
let mut components = path.components().peekable();
|
||||||
let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {
|
let mut ret = if let Some(c @ Component::Prefix(prefix_component)) = components.peek().cloned()
|
||||||
|
{
|
||||||
|
#[cfg(windows)]
|
||||||
|
// Remove only the Verbatim prefix, but keep the drive letter (e.g., C:\)
|
||||||
|
match prefix_component.kind() {
|
||||||
|
Prefix::VerbatimDisk(disk) => {
|
||||||
|
components.next(); // skip this prefix
|
||||||
|
// Re-add the disk prefix (e.g., C:)
|
||||||
|
let mut pb = PathBuf::new();
|
||||||
|
pb.push(format!("{}:", disk as char));
|
||||||
|
pb
|
||||||
|
}
|
||||||
|
Prefix::Verbatim(_) | Prefix::VerbatimUNC(_, _) => {
|
||||||
|
components.next(); // skip this prefix
|
||||||
|
PathBuf::new()
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
components.next();
|
components.next();
|
||||||
PathBuf::from(c.as_os_str())
|
PathBuf::from(c.as_os_str())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
{
|
||||||
|
components.next(); // skip this prefix
|
||||||
|
PathBuf::from(c.as_os_str())
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
PathBuf::new()
|
PathBuf::new()
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user