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: unify data folder

Vanalited1d9baa9c851
diff --git a/src-tauri/src/core/app/commands.rs b/src-tauri/src/core/app/commands.rs
index 3ce6c4ce4..ee46e3ec8 100644
--- a/src-tauri/src/core/app/commands.rs
+++ b/src-tauri/src/core/app/commands.rs
@@ -253,7 +253,7 @@ pub fn change_app_data_folder<R: Runtime>(
copy_dir_recursive(
&current_data_folder,
&new_data_folder_path,
- &[".uvx", ".npx"],
+ &[".uvx", ".npx", "openclaw/runtime", "openclaw/bunx"],
)
.map_err(|e| format!("Failed to copy data to new folder: {e}"))?;
} else {
diff --git a/src-tauri/src/core/openclaw/mod.rs b/src-tauri/src/core/openclaw/mod.rs
index ca3d6fc18..83ccfa89d 100644
--- a/src-tauri/src/core/openclaw/mod.rs
+++ b/src-tauri/src/core/openclaw/mod.rs
@@ -24,7 +24,6 @@ use tokio::sync::Mutex;
use sandbox::{Sandbox, SandboxMode};
use tunnels::TunnelState;
-/// When true, config dir resolves to `~/.openclaw/sandbox/docker/` instead of `~/.openclaw/`.
static DOCKER_MODE_ACTIVE: AtomicBool = AtomicBool::new(false);
pub fn set_docker_mode(active: bool) {
@@ -35,6 +34,17 @@ pub fn is_docker_mode() -> bool {
DOCKER_MODE_ACTIVE.load(Ordering::SeqCst)
}
+/// Base directory for all OpenClaw data, rooted under Jan's data folder.
+/// Returns `<jan_data_folder>/openclaw/`.
+pub fn get_openclaw_base_dir() -> Result<PathBuf, String> {
+ let jan_data = crate::core::app::commands::resolve_jan_data_folder();
+ let base = jan_data.join("openclaw");
+ if !base.exists() {
+ std::fs::create_dir_all(&base).map_err(|e| e.to_string())?;
+ }
+ Ok(base)
+}
+
/// OpenClaw configuration directory, isolated per sandbox mode.
pub fn get_openclaw_config_dir() -> Result<PathBuf, String> {
let home = dirs::home_dir().ok_or("Could not find home directory")?;
@@ -62,8 +72,8 @@ pub const MIN_BUN_VERSION: &str = "1.0";
/// OpenClaw runtime directory (where Bun and OpenClaw are installed)
pub fn get_openclaw_runtime_dir() -> Result<std::path::PathBuf, String> {
- let home = dirs::home_dir().ok_or("Could not find home directory")?;
- let runtime_dir = home.join(".jan").join("openclaw-runtime");
+ let base = get_openclaw_base_dir()?;
+ let runtime_dir = base.join("runtime");
if !runtime_dir.exists() {
std::fs::create_dir_all(&runtime_dir).map_err(|e| e.to_string())?;
}
diff --git a/src-tauri/src/core/openclaw/sandbox_direct.rs b/src-tauri/src/core/openclaw/sandbox_direct.rs
index e8b4cb442..2effec80b 100644
--- a/src-tauri/src/core/openclaw/sandbox_direct.rs
+++ b/src-tauri/src/core/openclaw/sandbox_direct.rs
@@ -4,9 +4,9 @@ use super::sandbox::{IsolationTier, Sandbox, SandboxConfig, SandboxHandle, Sandb
pub struct DirectProcessSandbox;
-/// Returns the BUN_INSTALL directory (`~/.jan/.bunx`), creating it if needed.
+/// Returns the BUN_INSTALL directory under Jan's data folder, creating it if needed.
fn get_bunx_dir() -> Option<std::path::PathBuf> {
- let dir = dirs::home_dir()?.join(".jan").join(".bunx");
+ let dir = super::get_openclaw_base_dir().ok()?.join("bunx");
if let Err(e) = std::fs::create_dir_all(&dir) {
log::warn!("Failed to create BUN_INSTALL dir {:?}: {}", dir, e);
}