diff --git a/src/devices.rs b/src/devices.rs index 1b34656..e8a08e1 100644 --- a/src/devices.rs +++ b/src/devices.rs @@ -3,7 +3,10 @@ use std::{collections::HashMap, io::Read, net::IpAddr, path::PathBuf, sync::Arc}; use log::{debug, info, trace, warn}; -use tokio::sync::{mpsc::UnboundedSender, Mutex}; +use tokio::{ + io::AsyncReadExt, + sync::{mpsc::UnboundedSender, Mutex}, +}; use crate::heartbeat; @@ -84,7 +87,7 @@ impl SharedDevices { } self.last_index += 1; self.last_interface_index += 1; - let pairing_file = self.get_pairing_record(udid.clone())?; + let pairing_file = self.get_pairing_record(udid.clone()).await?; let pairing_file = idevice::pairing_file::PairingFile::from_bytes(&pairing_file)?; let handle = if self.use_heartbeat { @@ -153,7 +156,7 @@ impl SharedDevices { .unwrap(); self.devices.remove(udid); } - pub fn get_pairing_record(&self, udid: String) -> Result, std::io::Error> { + pub async fn get_pairing_record(&self, udid: String) -> Result, std::io::Error> { let path = PathBuf::from(self.plist_storage.clone()).join(format!("{}.plist", udid)); info!("Attempting to read pairing file: {path:?}"); if !path.exists() { @@ -165,9 +168,9 @@ impl SharedDevices { } // Read the file info!("Reading pairing record for device: {:?}", udid); - let mut file = std::fs::File::open(path).unwrap(); + let mut file = tokio::fs::File::open(path).await?; let mut contents = Vec::new(); - file.read_to_end(&mut contents).unwrap(); + file.read_to_end(&mut contents).await?; Ok(contents) } pub fn get_buid(&self) -> Result { diff --git a/src/main.rs b/src/main.rs index b96b02e..d5bc8ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -382,21 +382,23 @@ async fn handle_stream( } "ReadPairRecord" => { let lock = data.lock().await; - let pair_file = match lock.get_pairing_record( - match parsed.plist.get("PairRecordID") { + let pair_file = match lock + .get_pairing_record(match parsed.plist.get("PairRecordID") { Some(plist::Value::String(p)) => p.to_owned(), _ => { warn!("Request did not contain PairRecordID"); return; } - }, - ) { + }) + .await + { Ok(pair_file) => pair_file, Err(_) => { // Unimplemented return; } }; + std::mem::drop(lock); let mut p = plist::Dictionary::new(); p.insert("PairRecordData".into(), plist::Value::Data(pair_file));