]> git.proxmox.com Git - proxmox-backup.git/commitdiff
protocol: add missing finish_backup to C API
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 13 Mar 2019 13:15:46 +0000 (14:15 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 13 Mar 2019 13:16:17 +0000 (14:16 +0100)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
proxmox-protocol/src/c_client.rs

index a3144bb9e9db7f6d27cd696a239f46b77191da93..d2cf4e4c25920dbe9b5560e8a523a082f76f8d16 100644 (file)
@@ -402,3 +402,41 @@ pub extern "C" fn proxmox_backup_fixed_data(
         })
     })
 }
+
+/// Finish a running backup.
+///
+/// Tells the server that the backup is supposed to be considered complete. If the request could be
+/// sent out entirely `1` is returned. If the underlying socket is non-blocking and the packet
+/// wasn't finished `0` is returned, after which `proxmox_backup_poll_send` should be used.
+///
+/// Once the request was sent out successfully, the client should wait for acknowledgement by the
+/// remote server via `proxmox_backup_wait_for_id`, passing the backup stream ID as parameter.
+///
+/// Finally, if the client wishes to know the exact name the server stored the file under, the
+/// `remote_path` parameter can be non-`NULL` to receive a string containing the file name, which
+/// must be freed by the caller!
+///
+/// Returns: `1` on success, possibly `0` for non-blocking I/O, `-1` on error.
+#[no_mangle]
+pub extern "C" fn proxmox_backup_finish_backup(
+    me: *mut CClient,
+    stream: c_int,
+    remote_path: *mut *mut c_char,
+) -> c_int {
+    let me = unsafe { &mut *me };
+    me.int_call(move |client| {
+        let (path, ack) = client.finish_backup(crate::BackupStream(stream as u8))?;
+
+        if !remote_path.is_null() {
+            // would be shorter with the unstable map_or_else
+            let cstr = CString::new(path)
+                .map(|cs| cs.into_raw())
+                .unwrap_or(std::ptr::null_mut());
+            unsafe {
+                *remote_path = cstr;
+            }
+        }
+
+        Ok(if ack { 1 } else { 0 })
+    })
+}