Persist `value` for the current shell session (keyed by the parent PID of this process).
(kind: SessionKind, value: &T)
| 70 | /// Persist `value` for the current shell session (keyed by the parent PID of |
| 71 | /// this process). |
| 72 | pub(crate) fn register<T: Serialize>(kind: SessionKind, value: &T) -> Result<()> { |
| 73 | let dir = get_root_dir(kind); |
| 74 | std::fs::create_dir_all(&dir)?; |
| 75 | |
| 76 | let parent_pid = |
| 77 | get_parent_pid(std::process::id() as pid_t).context("Could not determine parent PID")?; |
| 78 | |
| 79 | let path = get_state_file_path(&dir, parent_pid); |
| 80 | std::fs::write(path, serde_json::to_string(value)?)?; |
| 81 | Ok(()) |
| 82 | } |
| 83 | |
| 84 | /// Look up a previously-registered value by walking up the process tree from |
| 85 | /// this process. Returns `None` if no ancestor has registered a value. |
no test coverage detected