ssh_agency/agent/
files.rs

1use std::fs;
2use std::io::Result;
3
4use crate::agent::Agent;
5
6impl Agent {
7    pub fn clean_dead_agent_socket(&self) -> Result<()> {
8        if self.is_running {
9            println!(
10                "{} at {} is running and the socket can't be removed",
11                &self,
12                &self.socket_path.display()
13            );
14
15            return Err(std::io::Error::new(
16                std::io::ErrorKind::InvalidData,
17                "ssh-agent running",
18            ));
19        }
20
21        fs::remove_file(&self.socket_path)?;
22        let socket_dir = if let Some(dir) = &self.socket_path.parent() {
23            dir
24        } else {
25            self.socket_path.as_path()
26        };
27        fs::remove_dir(socket_dir)?;
28
29        Ok(())
30    }
31}