mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 06:26:15 +01:00
afc mkdir
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
// Jackson Coxson
|
// Jackson Coxson
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug, PartialEq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub enum AfcError {
|
pub enum AfcError {
|
||||||
|
|||||||
@@ -100,6 +100,32 @@ impl AfcClient {
|
|||||||
Ok(strings)
|
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(
|
pub async fn get_file_info(
|
||||||
&mut self,
|
&mut self,
|
||||||
path: impl Into<String>,
|
path: impl Into<String>,
|
||||||
@@ -190,7 +216,12 @@ impl AfcClient {
|
|||||||
return Err(IdeviceError::UnexpectedResponse);
|
return Err(IdeviceError::UnexpectedResponse);
|
||||||
}
|
}
|
||||||
let code = u64::from_le_bytes(res.header_payload[..8].try_into().unwrap());
|
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)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ async fn main() {
|
|||||||
.about("Lists the items in the directory")
|
.about("Lists the items in the directory")
|
||||||
.arg(Arg::new("path").required(true).index(1)),
|
.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(
|
.subcommand(
|
||||||
Command::new("remove")
|
Command::new("remove")
|
||||||
.about("Remove a provisioning profile")
|
.about("Remove a provisioning profile")
|
||||||
@@ -78,6 +83,9 @@ async fn main() {
|
|||||||
let path = matches.get_one::<String>("path").expect("No path passed");
|
let path = matches.get_one::<String>("path").expect("No path passed");
|
||||||
let res = afc_client.list_dir(path).await.expect("Failed to read dir");
|
let res = afc_client.list_dir(path).await.expect("Failed to read dir");
|
||||||
println!("{path}\n{res:#?}");
|
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") {
|
} else if let Some(matches) = matches.subcommand_matches("remove") {
|
||||||
let path = matches.get_one::<String>("id").expect("No path passed");
|
let path = matches.get_one::<String>("id").expect("No path passed");
|
||||||
} else if let Some(matches) = matches.subcommand_matches("info") {
|
} else if let Some(matches) = matches.subcommand_matches("info") {
|
||||||
|
|||||||
Reference in New Issue
Block a user