afc mkdir

This commit is contained in:
Jackson Coxson
2025-04-05 11:23:51 -06:00
parent 4d893e9d8c
commit 06766849f6
3 changed files with 41 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
// Jackson Coxson
#[derive(thiserror::Error, Debug)]
#[derive(thiserror::Error, Debug, PartialEq)]
#[non_exhaustive]
#[repr(C)]
pub enum AfcError {

View File

@@ -100,6 +100,32 @@ impl AfcClient {
Ok(strings)
}
pub async fn mk_dir(&mut self, path: impl Into<String>) -> Result<(), IdeviceError> {
let path = path.into();
let header_payload = path.as_bytes().to_vec();
let header_len = header_payload.len() as u64 + AfcPacketHeader::LEN;
let header = AfcPacketHeader {
magic: MAGIC,
entire_len: header_len, // it's the same since the payload is empty for this
header_payload_len: header_len,
packet_num: self.package_number,
operation: AfcOpcode::MakeDir,
};
self.package_number += 1;
let packet = AfcPacket {
header,
header_payload,
payload: Vec::new(),
};
self.send(packet).await?;
self.read().await?; // read a response to check for errors
Ok(())
}
pub async fn get_file_info(
&mut self,
path: impl Into<String>,
@@ -190,7 +216,12 @@ impl AfcClient {
return Err(IdeviceError::UnexpectedResponse);
}
let code = u64::from_le_bytes(res.header_payload[..8].try_into().unwrap());
return Err(IdeviceError::Afc(AfcError::from(code)));
let e = AfcError::from(code);
if e == AfcError::Success {
return Ok(res);
} else {
return Err(IdeviceError::Afc(e));
}
}
Ok(res)
}

View File

@@ -41,6 +41,11 @@ async fn main() {
.about("Lists the items in the directory")
.arg(Arg::new("path").required(true).index(1)),
)
.subcommand(
Command::new("mkdir")
.about("Creates a directory")
.arg(Arg::new("path").required(true).index(1)),
)
.subcommand(
Command::new("remove")
.about("Remove a provisioning profile")
@@ -78,6 +83,9 @@ async fn main() {
let path = matches.get_one::<String>("path").expect("No path passed");
let res = afc_client.list_dir(path).await.expect("Failed to read dir");
println!("{path}\n{res:#?}");
} else if let Some(matches) = matches.subcommand_matches("mkdir") {
let path = matches.get_one::<String>("path").expect("No path passed");
afc_client.mk_dir(path).await.expect("Failed to mkdir");
} else if let Some(matches) = matches.subcommand_matches("remove") {
let path = matches.get_one::<String>("id").expect("No path passed");
} else if let Some(matches) = matches.subcommand_matches("info") {