summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2020-01-12 01:24:56 +0100
committerGitHub <noreply@github.com>2020-01-12 01:24:56 +0100
commit09ed64bd365bdb294a29e2e6b0149b0581a1fa81 (patch)
treea6c8ba50b47b806f1bc82847198d070d66633984
parenta82df6ac4309f16bd1c75d13f1f4f1b9f79582eb (diff)
downloadalacritty-09ed64bd365bdb294a29e2e6b0149b0581a1fa81.tar.gz
alacritty-09ed64bd365bdb294a29e2e6b0149b0581a1fa81.zip
Fix crash with invalid working directory
-rw-r--r--CHANGELOG.md1
-rw-r--r--alacritty/src/cli.rs10
-rw-r--r--alacritty_terminal/src/config/mod.rs14
-rw-r--r--alacritty_terminal/src/tty/unix.rs2
-rw-r--r--alacritty_terminal/src/tty/windows/conpty.rs6
-rw-r--r--alacritty_terminal/src/tty/windows/winpty.rs2
6 files changed, 14 insertions, 21 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 345dfe34..eb7a7367 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Pressing additional modifiers for mouse bindings will no longer trigger them
- Renamed `WINIT_HIDPI_FACTOR` environment variable to `WINIT_X11_SCALE_FACTOR`
+- Print an error instead of crashing, when startup working directory is invalid
### Fixed
diff --git a/alacritty/src/cli.rs b/alacritty/src/cli.rs
index a7b97385..7e45e242 100644
--- a/alacritty/src/cli.rs
+++ b/alacritty/src/cli.rs
@@ -16,7 +16,7 @@ use std::cmp::max;
use std::path::PathBuf;
use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg};
-use log::{self, LevelFilter};
+use log::{self, error, LevelFilter};
use alacritty_terminal::config::{Delta, Dimensions, Shell, DEFAULT_NAME};
use alacritty_terminal::index::{Column, Line};
@@ -260,12 +260,14 @@ impl Options {
}
pub fn into_config(self, mut config: Config) -> Config {
+ match self.working_dir.or_else(|| config.working_directory.take()) {
+ Some(ref wd) if !wd.is_dir() => error!("Unable to set working directory to {:?}", wd),
+ wd => config.working_directory = wd,
+ }
+
if let Some(lcr) = self.live_config_reload {
config.set_live_config_reload(lcr);
}
- if let Some(wd) = self.working_dir {
- config.set_working_directory(Some(wd));
- }
config.shell = self.command.or(config.shell);
config.hold = self.hold;
diff --git a/alacritty_terminal/src/config/mod.rs b/alacritty_terminal/src/config/mod.rs
index f3257b7b..d077190b 100644
--- a/alacritty_terminal/src/config/mod.rs
+++ b/alacritty_terminal/src/config/mod.rs
@@ -15,7 +15,7 @@
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt::Display;
-use std::path::{Path, PathBuf};
+use std::path::PathBuf;
use log::error;
use serde::{Deserialize, Deserializer};
@@ -119,7 +119,7 @@ pub struct Config<T> {
/// Shell startup directory
#[serde(default, deserialize_with = "option_explicit_none")]
- working_directory: Option<PathBuf>,
+ pub working_directory: Option<PathBuf>,
/// Debug options
#[serde(default, deserialize_with = "failure_default")]
@@ -207,16 +207,6 @@ impl<T> Config<T> {
pub fn background_opacity(&self) -> f32 {
self.background_opacity.0
}
-
- #[inline]
- pub fn working_directory(&self) -> Option<&Path> {
- self.working_directory.as_ref().map(|path_buf| path_buf.as_path())
- }
-
- #[inline]
- pub fn set_working_directory(&mut self, working_directory: Option<PathBuf>) {
- self.working_directory = working_directory;
- }
}
#[serde(default)]
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs
index ab34d33a..1b01af0f 100644
--- a/alacritty_terminal/src/tty/unix.rs
+++ b/alacritty_terminal/src/tty/unix.rs
@@ -208,7 +208,7 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, window_id: Option<usize>) ->
}
// Handle set working directory option
- if let Some(ref dir) = config.working_directory() {
+ if let Some(dir) = &config.working_directory {
builder.current_dir(dir);
}
diff --git a/alacritty_terminal/src/tty/windows/conpty.rs b/alacritty_terminal/src/tty/windows/conpty.rs
index 28cdf4c4..0bed412b 100644
--- a/alacritty_terminal/src/tty/windows/conpty.rs
+++ b/alacritty_terminal/src/tty/windows/conpty.rs
@@ -204,9 +204,9 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, _window_id: Option<usize>) ->
let cmdline = win32_string(&cmdline(&config));
let cwd = config
- .working_directory()
- .map(|dir| dir.canonicalize().unwrap())
- .map(|path| win32_string(&path));
+ .working_directory
+ .as_ref()
+ .map(|pb| win32_string(&pb.as_path().canonicalize().unwrap()));
let mut proc_info: PROCESS_INFORMATION = Default::default();
unsafe {
diff --git a/alacritty_terminal/src/tty/windows/winpty.rs b/alacritty_terminal/src/tty/windows/winpty.rs
index c56ad8f6..2eccecbf 100644
--- a/alacritty_terminal/src/tty/windows/winpty.rs
+++ b/alacritty_terminal/src/tty/windows/winpty.rs
@@ -42,7 +42,7 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, _window_id: Option<usize>) ->
let (conin, conout) = (agent.conin_name(), agent.conout_name());
let cmdline = cmdline(&config);
- let cwd = config.working_directory().map(|dir| dir.canonicalize().unwrap());
+ let cwd = config.working_directory.as_ref().map(|pb| pb.as_path().canonicalize().unwrap());
// Spawn process
let spawnconfig = SpawnConfig::new(