@smbcloud / smbcloud-ascapi Mirror · read-only / commits / 645639d
Fork 0

Read-only mirror of github.com/smbcloudXYZ/smbcloud-ascapi.

Mirrored from https://github.com/smbcloudXYZ/smbcloud-ascapi.git

Synced Nov 25, 09:15 UTC

Reject empty upload plans and check --replace before a dry run

A reserve response with no upload operations for a non-empty file would have committed nothing under the full-file checksum, so upload_operations now refuses it. The dry run for review-screenshot and promotional-image used to describe a delete and upload even when the real run would stop and ask for --replace; the check now comes first. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: siGit Code v1.7.6 <noreply@sigit.si>

Seto Elkahfi committed Nov 4, 2026 at 19:41 UTC 645639df5639ef20b4bfa62021da8d58203779e9
2 files changed +32 -12
crates/cli/src/main.rs
+12 -12
@@ -4023,6 +4023,12 @@ async fn run_in_app_purchases(
4023 .context("the screenshot path has no file name")?
4024 .to_string();
4025 let existing = client.get_review_screenshot(&id).await?;
4026 + if let (Some(old), false) = (&existing, replace) {
4027 + anyhow::bail!(
4028 + "{id} already has a review screenshot ({}); pass --replace",
4029 + old.id
4030 + );
4031 + }
4032 if dry_run {
4033 println!(
4034 "# dry run: would {}upload {file_name} ({} bytes) as the review screenshot of {id}",
@@ -4032,12 +4038,6 @@ async fn run_in_app_purchases(
4038 return Ok(());
4039 }
4040 if let Some(old) = existing {
4035 - if !replace {
4036 - anyhow::bail!(
4037 - "{id} already has a review screenshot ({}); pass --replace",
4038 - old.id
4039 - );
4040 - }
4041 client.delete_review_screenshot(&old.id).await?;
4042 }
4043 let uploaded = client
@@ -4065,6 +4065,12 @@ async fn run_in_app_purchases(
4065 .context("the image path has no file name")?
4066 .to_string();
4067 let existing = client.list_promotional_images(&id).await?;
4068 + if !existing.is_empty() && !replace {
4069 + anyhow::bail!(
4070 + "{id} already has {} promotional image(s); pass --replace",
4071 + existing.len()
4072 + );
4073 + }
4074 if dry_run {
4075 println!(
4076 "# dry run: would {}upload {file_name} ({} bytes) as a promotional image of {id}",
@@ -4073,12 +4079,6 @@ async fn run_in_app_purchases(
4079 );
4080 return Ok(());
4081 }
4076 - if !existing.is_empty() && !replace {
4077 - anyhow::bail!(
4078 - "{id} already has {} promotional image(s); pass --replace",
4079 - existing.len()
4080 - );
4081 - }
4082 for old in &existing {
4083 client.delete_promotional_image(&old.id).await?;
4084 }
crates/iap/src/review_screenshot.rs
+20
@@ -121,12 +121,25 @@ fn chunk_for(op: &UploadOperation, bytes: &[u8]) -> Result<Vec<u8>> {
121 })
122 }
123
124 +/// Refuse an upload plan that cannot deliver `bytes`: a non-empty file with
125 +/// no operations at all would commit nothing under the full-file checksum.
126 +fn check_plan(operations: &[UploadOperation], bytes: &[u8]) -> Result<()> {
127 + if !bytes.is_empty() && operations.is_empty() {
128 + return Err(Error::UploadPlan(format!(
129 + "the reserve response carried no upload operations for a {}-byte file",
130 + bytes.len()
131 + )));
132 + }
133 + Ok(())
134 +}
135 +
136 /// PUT each slice of `bytes` that Apple's upload operations ask for.
137 pub(crate) async fn upload_operations(
138 client: &Client,
139 operations: &[UploadOperation],
140 bytes: &[u8],
141 ) -> Result<()> {
142 + check_plan(operations, bytes)?;
143 for op in operations {
144 let chunk = chunk_for(op, bytes)?;
145 let headers: Vec<(String, String)> = op
@@ -269,4 +282,11 @@ mod tests {
282 ));
283 assert!(chunk_for(&op(u64::MAX, 10), b"abc").is_err());
284 }
285 +
286 + #[test]
287 + fn no_operations_for_a_non_empty_file_is_an_error() {
288 + assert!(matches!(check_plan(&[], b"abc"), Err(Error::UploadPlan(_))));
289 + assert!(check_plan(&[], b"").is_ok());
290 + assert!(check_plan(&[op(0, 3)], b"abc").is_ok());
291 + }
292 }