Skip to content

Commit

Permalink
persist charselect, repl history and others in data dir
Browse files Browse the repository at this point in the history
We were using the runtime dir with a fallback to a directory
that was equivalent to the data dir on !xdg systems.  That
meant that the state in the runtime dir was often scrubbed
around a reboot.

refs: #4019
refs: #4047
  • Loading branch information
wez committed Jul 22, 2023
1 parent 3e3df82 commit a07ab88
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 7 deletions.
8 changes: 8 additions & 0 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,14 @@ fn default_font_size() -> f64 {
12.0
}

pub(crate) fn compute_data_dir() -> anyhow::Result<PathBuf> {
if let Some(runtime) = dirs_next::data_dir() {
return Ok(runtime.join("wezterm"));
}

Ok(crate::HOME_DIR.join(".local/share/wezterm"))
}

pub(crate) fn compute_runtime_dir() -> anyhow::Result<PathBuf> {
if let Some(runtime) = dirs_next::runtime_dir() {
return Ok(runtime.join("wezterm"));
Expand Down
1 change: 1 addition & 0 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ lazy_static! {
pub static ref HOME_DIR: PathBuf = dirs_next::home_dir().expect("can't find HOME dir");
pub static ref CONFIG_DIRS: Vec<PathBuf> = config_dirs();
pub static ref RUNTIME_DIR: PathBuf = compute_runtime_dir().unwrap();
pub static ref DATA_DIR: PathBuf = compute_data_dir().unwrap();
static ref CONFIG: Configuration = Configuration::new();
static ref CONFIG_FILE_OVERRIDE: Mutex<Option<PathBuf>> = Mutex::new(None);
static ref CONFIG_SKIP: AtomicBool = AtomicBool::new(false);
Expand Down
2 changes: 1 addition & 1 deletion config/src/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub fn make_lua_context(config_file: &Path) -> anyhow::Result<Lua> {
}
path_array.insert(
2,
format!("{}/plugins/?/plugin/init.lua", crate::RUNTIME_DIR.display()),
format!("{}/plugins/?/plugin/init.lua", crate::DATA_DIR.display()),
);

if let Ok(exe) = std::env::current_exe() {
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ As features stabilize some brief notes about them will accumulate here.
* Windows: couldn't use shifted keys like `(` in the Debug Overlay. #3999
* X11: fd leak on each call to
[wezterm.gui.enumerate_gpus](config/lua/wezterm.gui/enumerate_gpus.md). #3612
* Charselect and repl recency/history were not persisted across restarts. #4047 ?4019

### 20230712-072601-f4abf8fd

Expand Down
2 changes: 1 addition & 1 deletion lua-api-crates/plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl RepoSpec {
}

fn plugins_dir() -> PathBuf {
config::RUNTIME_DIR.join("plugins")
config::DATA_DIR.join("plugins")
}

fn checkout_path(&self) -> PathBuf {
Expand Down
2 changes: 1 addition & 1 deletion wezterm-gui/src/overlay/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct LuaReplHost {
}

fn history_file_name() -> PathBuf {
config::RUNTIME_DIR.join("repl-history")
config::DATA_DIR.join("repl-history")
}

impl LuaReplHost {
Expand Down
2 changes: 1 addition & 1 deletion wezterm-gui/src/termwindow/charselect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct Recent {
}

fn recent_file_name() -> PathBuf {
config::RUNTIME_DIR.join("recent-emoji.json")
config::DATA_DIR.join("recent-emoji.json")
}

fn load_recents() -> anyhow::Result<Vec<Recent>> {
Expand Down
2 changes: 1 addition & 1 deletion wezterm-gui/src/termwindow/palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct Recent {
}

fn recent_file_name() -> PathBuf {
config::RUNTIME_DIR.join("recent-commands.json")
config::DATA_DIR.join("recent-commands.json")
}

fn load_recents() -> anyhow::Result<Vec<Recent>> {
Expand Down
4 changes: 2 additions & 2 deletions wezterm-gui/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ pub fn load_last_release_info_and_set_banner() {
return;
}

let update_file_name = config::RUNTIME_DIR.join("check_update");
let update_file_name = config::DATA_DIR.join("check_update");
if let Ok(data) = std::fs::read(update_file_name) {
let latest: Release = match serde_json::from_slice(&data) {
Ok(d) => d,
Expand Down Expand Up @@ -351,7 +351,7 @@ fn update_checker() {

let force_ui = std::env::var_os("WEZTERM_ALWAYS_SHOW_UPDATE_UI").is_some();

let update_file_name = config::RUNTIME_DIR.join("check_update");
let update_file_name = config::DATA_DIR.join("check_update");
let delay = update_file_name
.metadata()
.and_then(|metadata| metadata.modified())
Expand Down

0 comments on commit a07ab88

Please sign in to comment.