mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
tpm: remove mixture of str and Path
`impl AsRef<Path>` is the most idiomatic way to consume paths in Rust. I removed the mixture. Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de> On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
committed by
Rob Bradford
parent
c53781bf5f
commit
afcb2b285f
@@ -6,6 +6,7 @@
|
||||
use std::io::Read;
|
||||
use std::os::unix::io::{AsRawFd, RawFd};
|
||||
use std::os::unix::net::UnixStream;
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use log::debug;
|
||||
@@ -58,21 +59,23 @@ impl SocketDev {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(&mut self, path: &str) -> Result<()> {
|
||||
pub fn init(&mut self, path: impl AsRef<Path>) -> Result<()> {
|
||||
self.connect(path)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn connect(&mut self, socket_path: &str) -> Result<()> {
|
||||
pub fn connect(&mut self, socket_path: impl AsRef<Path>) -> Result<()> {
|
||||
let socket_path = socket_path.as_ref();
|
||||
self.state = SocketDevState::Connecting;
|
||||
|
||||
let socket_path_s = socket_path.to_str().unwrap();
|
||||
let s = UnixStream::connect(socket_path).map_err(|e| {
|
||||
Error::ConnectToSocket(anyhow!("Failed to connect to tpm Socket. Error: {e:?}"))
|
||||
})?;
|
||||
self.control_fd = s.as_raw_fd();
|
||||
self.stream = Some(s);
|
||||
self.state = SocketDevState::Connected;
|
||||
debug!("Connected to tpm socket path : {socket_path:?}");
|
||||
debug!("Connected to tpm socket path : {socket_path_s:?}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user