diff --git a/current-api.h b/current-api.h index d5861d0..4e32a76 100644 --- a/current-api.h +++ b/current-api.h @@ -199,7 +199,13 @@ void proxmox_backup_register_image_async(ProxmoxBackupHandle *handle, * * Upload a chunk of data for the image. * - * data may be NULL in order to write the zero chunk (only allowed if size == chunk_size) + * The data pointer may be NULL in order to write the zero chunk + * (only allowed if size == chunk_size) + * + * Returns: + * -1: on error + * 0: successful, chunk already exists on server, so it was resued + * size: successful, chunk uploaded */ int proxmox_backup_write_data(ProxmoxBackupHandle *handle, uint8_t dev_id, @@ -218,6 +224,11 @@ int proxmox_backup_write_data(ProxmoxBackupHandle *handle, * * Note: The data pointer needs to be valid until the async * opteration is finished. + * + * Returns: + * -1: on error + * 0: successful, chunk already exists on server, so it was resued + * size: successful, chunk uploaded */ void proxmox_backup_write_data_async(ProxmoxBackupHandle *handle, uint8_t dev_id, diff --git a/src/commands.rs b/src/commands.rs index bee1b11..78cf0cf 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -274,12 +274,15 @@ pub(crate) async fn write_data( (info.wid, info.upload_queue.clone(), info.zero_chunk_digest) }; + let mut reused = false; + let upload_future: Box> + Send + Unpin> = { if data.0.is_null() { if size != chunk_size { bail!("write_data: got invalid null chunk"); } let upload_info = ChunkUploadInfo { digest: zero_chunk_digest, offset, size, chunk_is_known: true }; + reused = true; Box::new(futures::future::ok(upload_info)) } else { let data: &[u8] = unsafe { std::slice::from_raw_parts(data.0, size as usize) }; @@ -299,6 +302,7 @@ pub(crate) async fn write_data( if chunk_is_known { let upload_info = ChunkUploadInfo { digest: *digest, offset, size, chunk_is_known: true }; + reused = true; Box::new(futures::future::ok(upload_info)) } else { let (chunk, digest) = chunk_builder.build()?; @@ -363,7 +367,7 @@ pub(crate) async fn write_data( //println!("upload chunk sucessful"); - Ok(size as c_int) + Ok(if reused { 0 } else { size as c_int }) } pub(crate) async fn finish_backup( diff --git a/src/lib.rs b/src/lib.rs index fb52ead..7d3d471 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -387,7 +387,13 @@ pub extern "C" fn proxmox_backup_add_config_async( /// /// Upload a chunk of data for the image. /// -/// data may be NULL in order to write the zero chunk (only allowed if size == chunk_size) +/// The data pointer may be NULL in order to write the zero chunk +/// (only allowed if size == chunk_size) +/// +/// Returns: +/// -1: on error +/// 0: successful, chunk already exists on server, so it was resued +/// size: successful, chunk uploaded #[no_mangle] #[allow(clippy::not_unsafe_ptr_arg_deref)] pub extern "C" fn proxmox_backup_write_data( @@ -426,6 +432,11 @@ pub extern "C" fn proxmox_backup_write_data( /// /// Note: The data pointer needs to be valid until the async /// opteration is finished. +/// +/// Returns: +/// -1: on error +/// 0: successful, chunk already exists on server, so it was resued +/// size: successful, chunk uploaded #[no_mangle] #[allow(clippy::not_unsafe_ptr_arg_deref)] pub extern "C" fn proxmox_backup_write_data_async(