diff options
author | Jae-Heon Ji <32578710+jaeheonji@users.noreply.github.com> | 2022-01-13 20:41:13 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-13 20:41:13 +0900 |
commit | 65a12c0f5e641dc494df1f60c3942c63ccae4858 (patch) | |
tree | 6e19bddb1e4ba65b3514f33e067b36c0c63e505a /zellij-server/src/os_input_output.rs | |
parent | f6c56f6ea3730aea170db4bc19d30fa4471375d1 (diff) |
feat: change dependency for `process_cwd` (#1001)
* feat: change dependency for process_cwd
* test: add unittest for get_cwd
* chore: apply clippy
* test: change tty to openpty
* test(e2e): update case
Diffstat (limited to 'zellij-server/src/os_input_output.rs')
-rw-r--r-- | zellij-server/src/os_input_output.rs | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/zellij-server/src/os_input_output.rs b/zellij-server/src/os_input_output.rs index 50add7500..f0b49c68b 100644 --- a/zellij-server/src/os_input_output.rs +++ b/zellij-server/src/os_input_output.rs @@ -2,12 +2,6 @@ use std::collections::HashMap; use crate::panes::PaneId; -#[cfg(target_os = "macos")] -use darwin_libproc; - -#[cfg(target_os = "linux")] -use std::fs; - use std::env; use std::os::unix::io::RawFd; use std::os::unix::process::CommandExt; @@ -21,6 +15,8 @@ use async_std::fs::File as AsyncFile; use async_std::os::unix::io::FromRawFd; use interprocess::local_socket::LocalSocketStream; +use sysinfo::{ProcessExt, ProcessRefreshKind, System, SystemExt}; + use nix::pty::{openpty, OpenptyResult, Winsize}; use nix::sys::signal::{kill, Signal}; use nix::sys::termios; @@ -338,16 +334,15 @@ impl ServerOsApi for ServerOsInputOutput { fn load_palette(&self) -> Palette { default_palette() } - #[cfg(target_os = "macos")] - fn get_cwd(&self, pid: Pid) -> Option<PathBuf> { - darwin_libproc::pid_cwd(pid.as_raw()).ok() - } - #[cfg(target_os = "linux")] fn get_cwd(&self, pid: Pid) -> Option<PathBuf> { - fs::read_link(format!("/proc/{}/cwd", pid)).ok() - } - #[cfg(all(not(target_os = "linux"), not(target_os = "macos")))] - fn get_cwd(&self, _pid: Pid) -> Option<PathBuf> { + let mut system_info = System::new(); + // Update by minimizing information. + // See https://docs.rs/sysinfo/0.22.5/sysinfo/struct.ProcessRefreshKind.html# + system_info.refresh_processes_specifics(ProcessRefreshKind::default()); + + if let Some(process) = system_info.process(pid.into()) { + return Some(process.cwd().to_path_buf()); + } None } } @@ -376,3 +371,7 @@ pub struct ChildId { /// field is it's parent process id. pub shell: Option<Pid>, } + +#[cfg(test)] +#[path = "./unit/os_input_output_tests.rs"] +mod os_input_output_tests; |