mirror of
https://git.proxmox.com/git/proxmox-backup-qemu
synced 2025-10-04 20:15:22 +00:00
clippy lints
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
642925ba64
commit
a2841b1b2b
@ -96,7 +96,7 @@ impl BackupTask {
|
||||
}
|
||||
|
||||
pub fn abort(&self, reason: String) {
|
||||
if let Err(_) = self.abort.send(()) {
|
||||
if self.abort.send(()).is_err() {
|
||||
// should not happen, but log to stderr
|
||||
eprintln!("BackupTask send abort failed.");
|
||||
}
|
||||
@ -144,13 +144,13 @@ impl BackupTask {
|
||||
self.check_aborted()?;
|
||||
|
||||
let writer = match self.writer.get() {
|
||||
Some(writer) => writer.clone(),
|
||||
Some(writer) => Arc::clone(writer),
|
||||
None => bail!("not connected"),
|
||||
};
|
||||
|
||||
let command_future = add_config(
|
||||
writer,
|
||||
self.manifest.clone(),
|
||||
Arc::clone(&self.manifest),
|
||||
name,
|
||||
data,
|
||||
self.compress,
|
||||
@ -172,15 +172,15 @@ impl BackupTask {
|
||||
self.check_aborted()?;
|
||||
|
||||
let writer = match self.writer.get() {
|
||||
Some(writer) => writer.clone(),
|
||||
Some(writer) => Arc::clone(writer),
|
||||
None => bail!("not connected"),
|
||||
};
|
||||
|
||||
let command_future = write_data(
|
||||
writer,
|
||||
if self.crypt_mode == CryptMode::Encrypt { self.crypt_config.clone() } else { None },
|
||||
self.registry.clone(),
|
||||
self.known_chunks.clone(),
|
||||
Arc::clone(&self.registry),
|
||||
Arc::clone(&self.known_chunks),
|
||||
dev_id,
|
||||
data,
|
||||
offset,
|
||||
@ -194,7 +194,7 @@ impl BackupTask {
|
||||
}
|
||||
|
||||
fn last_manifest(&self) -> Option<Arc<BackupManifest>> {
|
||||
self.last_manifest.get().map(|m| m.clone())
|
||||
self.last_manifest.get().map(Arc::clone)
|
||||
}
|
||||
|
||||
pub fn check_incremental(
|
||||
@ -204,8 +204,8 @@ impl BackupTask {
|
||||
) -> bool {
|
||||
match self.last_manifest() {
|
||||
Some(ref manifest) => {
|
||||
check_last_incremental_csum(manifest.clone(), &device_name, size)
|
||||
&& check_last_encryption_mode(manifest.clone(), &device_name, self.crypt_mode)
|
||||
check_last_incremental_csum(Arc::clone(manifest), &device_name, size)
|
||||
&& check_last_encryption_mode(Arc::clone(manifest), &device_name, self.crypt_mode)
|
||||
},
|
||||
None => false,
|
||||
}
|
||||
@ -221,7 +221,7 @@ impl BackupTask {
|
||||
self.check_aborted()?;
|
||||
|
||||
let writer = match self.writer.get() {
|
||||
Some(writer) => writer.clone(),
|
||||
Some(writer) => Arc::clone(writer),
|
||||
None => bail!("not connected"),
|
||||
};
|
||||
|
||||
@ -229,9 +229,9 @@ impl BackupTask {
|
||||
writer,
|
||||
self.crypt_config.clone(),
|
||||
self.crypt_mode,
|
||||
self.last_manifest.get().map(|m| m.clone()),
|
||||
self.registry.clone(),
|
||||
self.known_chunks.clone(),
|
||||
self.last_manifest.get().map(Arc::clone),
|
||||
Arc::clone(&self.registry),
|
||||
Arc::clone(&self.known_chunks),
|
||||
device_name,
|
||||
size,
|
||||
self.setup.chunk_size,
|
||||
@ -247,14 +247,14 @@ impl BackupTask {
|
||||
self.check_aborted()?;
|
||||
|
||||
let writer = match self.writer.get() {
|
||||
Some(writer) => writer.clone(),
|
||||
Some(writer) => Arc::clone(writer),
|
||||
None => bail!("not connected"),
|
||||
};
|
||||
|
||||
let command_future = close_image(
|
||||
writer,
|
||||
self.manifest.clone(),
|
||||
self.registry.clone(),
|
||||
Arc::clone(&self.manifest),
|
||||
Arc::clone(&self.registry),
|
||||
dev_id,
|
||||
self.crypt_mode,
|
||||
);
|
||||
@ -268,11 +268,15 @@ impl BackupTask {
|
||||
self.check_aborted()?;
|
||||
|
||||
let writer = match self.writer.get() {
|
||||
Some(writer) => writer.clone(),
|
||||
Some(writer) => Arc::clone(writer),
|
||||
None => bail!("not connected"),
|
||||
};
|
||||
|
||||
let command_future = finish_backup(writer, self.crypt_config.clone(), self.manifest.clone());
|
||||
let command_future = finish_backup(
|
||||
writer,
|
||||
self.crypt_config.clone(),
|
||||
Arc::clone(&self.manifest),
|
||||
);
|
||||
|
||||
let mut abort_rx = self.abort.subscribe();
|
||||
abortable_command(command_future, abort_rx.recv()).await
|
||||
|
@ -114,7 +114,7 @@ pub(crate) fn check_last_encryption_mode(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) async fn register_image(
|
||||
client: Arc<BackupWriter>,
|
||||
crypt_config: Option<Arc<CryptConfig>>,
|
||||
@ -132,7 +132,7 @@ pub(crate) async fn register_image(
|
||||
|
||||
let index = match manifest {
|
||||
Some(manifest) => {
|
||||
match client.download_previous_fixed_index(&archive_name, &manifest, known_chunks.clone()).await {
|
||||
match client.download_previous_fixed_index(&archive_name, &manifest, Arc::clone(&known_chunks)).await {
|
||||
Ok(index) => Some(index),
|
||||
// not having a previous index is not fatal, so ignore errors
|
||||
Err(_) => None
|
||||
@ -179,16 +179,16 @@ pub(crate) async fn register_image(
|
||||
let wid = client.post("fixed_index", Some(param)).await?.as_u64().unwrap();
|
||||
|
||||
let zero_chunk_digest = register_zero_chunk(
|
||||
client.clone(),
|
||||
Arc::clone(&client),
|
||||
if crypt_mode == CryptMode::Encrypt { crypt_config } else { None },
|
||||
chunk_size as usize,
|
||||
wid,
|
||||
).await?;
|
||||
|
||||
let (upload_queue, upload_result) = create_upload_queue(
|
||||
client.clone(),
|
||||
known_chunks.clone(),
|
||||
initial_index.clone(),
|
||||
Arc::clone(&client),
|
||||
Arc::clone(&known_chunks),
|
||||
Arc::clone(&initial_index),
|
||||
wid,
|
||||
device_size,
|
||||
chunk_size,
|
||||
|
28
src/lib.rs
28
src/lib.rs
@ -1,3 +1,5 @@
|
||||
#![warn(clippy::clone_on_ref_ptr)]
|
||||
|
||||
use anyhow::{format_err, Error};
|
||||
use std::ffi::CString;
|
||||
use std::ptr;
|
||||
@ -152,7 +154,7 @@ impl GotResultCondition {
|
||||
callback: Self::wakeup_callback,
|
||||
callback_data: (self) as *mut _ as *mut c_void,
|
||||
error,
|
||||
result: result,
|
||||
result,
|
||||
}
|
||||
}
|
||||
|
||||
@ -246,7 +248,7 @@ pub extern "C" fn proxmox_backup_new(
|
||||
fn backup_handle_to_task(handle: *mut ProxmoxBackupHandle) -> Arc<BackupTask> {
|
||||
let task = unsafe { & *(handle as *const Arc<BackupTask>) };
|
||||
// increase reference count while we use it inside rust
|
||||
task.clone()
|
||||
Arc::clone(task)
|
||||
}
|
||||
|
||||
/// Open connection to the backup server (sync)
|
||||
@ -277,7 +279,7 @@ pub extern "C" fn proxmox_backup_connect(
|
||||
|
||||
got_result_condition.wait();
|
||||
|
||||
return result;
|
||||
result
|
||||
}
|
||||
|
||||
/// Open connection to the backup server
|
||||
@ -317,7 +319,7 @@ pub extern "C" fn proxmox_backup_abort(
|
||||
) {
|
||||
let task = backup_handle_to_task(handle);
|
||||
let reason = tools::utf8_c_string_lossy(reason)
|
||||
.unwrap_or(String::from("no reason (NULL)"));
|
||||
.unwrap_or_else(|| "no reason (NULL)".to_string());
|
||||
task.abort(reason);
|
||||
}
|
||||
|
||||
@ -368,7 +370,7 @@ pub extern "C" fn proxmox_backup_register_image(
|
||||
|
||||
got_result_condition.wait();
|
||||
|
||||
return result;
|
||||
result
|
||||
}
|
||||
|
||||
/// Register a backup image
|
||||
@ -427,7 +429,7 @@ pub extern "C" fn proxmox_backup_add_config(
|
||||
|
||||
got_result_condition.wait();
|
||||
|
||||
return result;
|
||||
result
|
||||
}
|
||||
|
||||
/// Add a configuration blob to the backup
|
||||
@ -498,7 +500,7 @@ pub extern "C" fn proxmox_backup_write_data(
|
||||
|
||||
got_result_condition.wait();
|
||||
|
||||
return result;
|
||||
result
|
||||
}
|
||||
|
||||
/// Write data to into a registered image
|
||||
@ -563,7 +565,7 @@ pub extern "C" fn proxmox_backup_close_image(
|
||||
|
||||
got_result_condition.wait();
|
||||
|
||||
return result;
|
||||
result
|
||||
}
|
||||
|
||||
/// Close a registered image
|
||||
@ -611,7 +613,7 @@ pub extern "C" fn proxmox_backup_finish(
|
||||
|
||||
got_result_condition.wait();
|
||||
|
||||
return result;
|
||||
result
|
||||
}
|
||||
|
||||
/// Finish the backup
|
||||
@ -655,7 +657,7 @@ pub extern "C" fn proxmox_backup_disconnect(handle: *mut ProxmoxBackupHandle) {
|
||||
fn restore_handle_to_task(handle: *mut ProxmoxRestoreHandle) -> Arc<RestoreTask> {
|
||||
let restore_task = unsafe { & *(handle as *const Arc<RestoreTask>) };
|
||||
// increase reference count while we use it inside rust
|
||||
restore_task.clone()
|
||||
Arc::clone(restore_task)
|
||||
}
|
||||
|
||||
/// Connect the the backup server for restore (sync)
|
||||
@ -742,7 +744,7 @@ pub extern "C" fn proxmox_restore_connect(
|
||||
|
||||
got_result_condition.wait();
|
||||
|
||||
return result;
|
||||
result
|
||||
}
|
||||
/// Open connection to the backup server (async)
|
||||
///
|
||||
@ -843,7 +845,7 @@ pub extern "C" fn proxmox_restore_open_image(
|
||||
|
||||
got_result_condition.wait();
|
||||
|
||||
return result;
|
||||
result
|
||||
}
|
||||
|
||||
/// Retrieve the ID of a handle used to access data in the given archive (async)
|
||||
@ -923,7 +925,7 @@ pub extern "C" fn proxmox_restore_read_image_at(
|
||||
|
||||
got_result_condition.wait();
|
||||
|
||||
return result;
|
||||
result
|
||||
}
|
||||
|
||||
/// Read data from the backup image at the given offset (async)
|
||||
|
@ -119,12 +119,12 @@ impl RestoreTask {
|
||||
}
|
||||
|
||||
let client = match self.client.get() {
|
||||
Some(reader) => reader.clone(),
|
||||
Some(reader) => Arc::clone(reader),
|
||||
None => bail!("not connected"),
|
||||
};
|
||||
|
||||
let manifest = match self.manifest.get() {
|
||||
Some(manifest) => manifest.clone(),
|
||||
Some(manifest) => Arc::clone(manifest),
|
||||
None => bail!("no manifest"),
|
||||
};
|
||||
|
||||
@ -141,7 +141,7 @@ impl RestoreTask {
|
||||
let file_info = manifest.lookup_file_info(&archive_name)?;
|
||||
|
||||
let mut chunk_reader = RemoteChunkReader::new(
|
||||
client.clone(),
|
||||
Arc::clone(&client),
|
||||
self.crypt_config.clone(),
|
||||
file_info.chunk_crypt_mode(),
|
||||
most_used,
|
||||
@ -206,12 +206,12 @@ impl RestoreTask {
|
||||
) -> Result<u8, Error> {
|
||||
|
||||
let client = match self.client.get() {
|
||||
Some(reader) => reader.clone(),
|
||||
Some(reader) => Arc::clone(reader),
|
||||
None => bail!("not connected"),
|
||||
};
|
||||
|
||||
let manifest = match self.manifest.get() {
|
||||
Some(manifest) => manifest.clone(),
|
||||
Some(manifest) => Arc::clone(manifest),
|
||||
None => bail!("no manifest"),
|
||||
};
|
||||
|
||||
@ -222,7 +222,7 @@ impl RestoreTask {
|
||||
let file_info = manifest.lookup_file_info(&archive_name)?;
|
||||
|
||||
let chunk_reader = RemoteChunkReader::new(
|
||||
client.clone(),
|
||||
Arc::clone(&client),
|
||||
self.crypt_config.clone(),
|
||||
file_info.chunk_crypt_mode(),
|
||||
most_used,
|
||||
@ -250,7 +250,7 @@ impl RestoreTask {
|
||||
let (reader, image_size) = {
|
||||
let mut guard = self.image_registry.lock().unwrap();
|
||||
let info = guard.lookup(aid)?;
|
||||
(info.reader.clone(), info.archive_size)
|
||||
(Arc::clone(&info.reader), info.archive_size)
|
||||
};
|
||||
|
||||
if offset > image_size {
|
||||
|
@ -70,6 +70,7 @@ async fn upload_chunk_list(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn upload_handler(
|
||||
client: Arc<BackupWriter>,
|
||||
known_chunks: Arc<Mutex<HashSet<[u8;32]>>>,
|
||||
@ -119,7 +120,12 @@ async fn upload_handler(
|
||||
offset_list.push(offset);
|
||||
|
||||
if digest_list.len() >= 128 {
|
||||
if let Err(err) = upload_chunk_list(client.clone(), wid, &mut digest_list, &mut offset_list).await {
|
||||
if let Err(err) = upload_chunk_list(
|
||||
Arc::clone(&client),
|
||||
wid,
|
||||
&mut digest_list,
|
||||
&mut offset_list,
|
||||
).await {
|
||||
let _ = upload_result.send(Err(err));
|
||||
return;
|
||||
}
|
||||
@ -133,7 +139,12 @@ async fn upload_handler(
|
||||
}
|
||||
|
||||
if !digest_list.is_empty() {
|
||||
if let Err(err) = upload_chunk_list(client.clone(), wid, &mut digest_list, &mut offset_list).await {
|
||||
if let Err(err) = upload_chunk_list(
|
||||
Arc::clone(&client),
|
||||
wid,
|
||||
&mut digest_list,
|
||||
&mut offset_list,
|
||||
).await {
|
||||
let _ = upload_result.send(Err(err));
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user