Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix: model download - windows path issue

Louisa8ed759a06b9
diff --git a/src-tauri/src/core/utils/download.rs b/src-tauri/src/core/utils/download.rs
index ae34df25c..b7730ed25 100644
--- a/src-tauri/src/core/utils/download.rs
+++ b/src-tauri/src/core/utils/download.rs
@@ -4,8 +4,6 @@ use crate::core::utils::normalize_path;
use futures_util::StreamExt;
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
use std::collections::HashMap;
-use std::path::Component;
-use std::path::Prefix;
use std::time::Duration;
use tauri::{Emitter, State};
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 = 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) {
return Err(format!(
"Path {} is outside of Jan data folder {}",
diff --git a/src-tauri/src/core/utils/mod.rs b/src-tauri/src/core/utils/mod.rs
index 2a144eafb..1df4e5231 100644
--- a/src-tauri/src/core/utils/mod.rs
+++ b/src-tauri/src/core/utils/mod.rs
@@ -6,6 +6,7 @@ use std::path::{Component, Path, PathBuf};
use tauri::Runtime;
use super::cmd::get_jan_data_folder_path;
+use std::path::Prefix;
pub const THREADS_DIR: &str = "threads";
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
pub fn normalize_path(path: &Path) -> PathBuf {
let mut components = path.components().peekable();
- let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {
- components.next();
- PathBuf::from(c.as_os_str())
+ 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();
+ PathBuf::from(c.as_os_str())
+ }
+ }
+ #[cfg(not(windows))]
+ {
+ components.next(); // skip this prefix
+ PathBuf::from(c.as_os_str())
+ }
} else {
PathBuf::new()
};