afc write file

This commit is contained in:
Jackson Coxson
2025-04-06 11:53:45 -06:00
parent 7b0590b7ae
commit 1a7534a106
2 changed files with 55 additions and 3 deletions

View File

@@ -1,6 +1,8 @@
// Jackson Coxson
use clap::{Arg, Command};
use std::path::PathBuf;
use clap::{value_parser, Arg, Command};
use idevice::{
afc::{opcode::AfcFopenMode, AfcClient},
IdeviceService,
@@ -48,6 +50,17 @@ async fn main() {
.arg(Arg::new("path").required(true).index(1))
.arg(Arg::new("save").required(true).index(2)),
)
.subcommand(
Command::new("upload")
.about("Creates a directory")
.arg(
Arg::new("file")
.required(true)
.index(1)
.value_parser(value_parser!(PathBuf)),
)
.arg(Arg::new("path").required(true).index(2)),
)
.subcommand(
Command::new("mkdir")
.about("Creates a directory")
@@ -112,6 +125,17 @@ async fn main() {
tokio::fs::write(save, res)
.await
.expect("Failed to write to file");
} else if let Some(matches) = matches.subcommand_matches("upload") {
let file = matches.get_one::<PathBuf>("file").expect("No path passed");
let path = matches.get_one::<String>("path").expect("No path passed");
let bytes = tokio::fs::read(file).await.expect("Failed to read file");
let mut file = afc_client
.open(path, AfcFopenMode::WrOnly)
.await
.expect("Failed to open");
file.write(&bytes).await.expect("Failed to upload bytes");
} else if let Some(matches) = matches.subcommand_matches("remove") {
let path = matches.get_one::<String>("path").expect("No path passed");
afc_client.remove(path).await.expect("Failed to remove");