clippy lints

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2020-08-13 09:50:55 +02:00
parent 642925ba64
commit a2841b1b2b
5 changed files with 63 additions and 46 deletions

View File

@ -96,7 +96,7 @@ impl BackupTask {
} }
pub fn abort(&self, reason: String) { 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 // should not happen, but log to stderr
eprintln!("BackupTask send abort failed."); eprintln!("BackupTask send abort failed.");
} }
@ -144,13 +144,13 @@ impl BackupTask {
self.check_aborted()?; self.check_aborted()?;
let writer = match self.writer.get() { let writer = match self.writer.get() {
Some(writer) => writer.clone(), Some(writer) => Arc::clone(writer),
None => bail!("not connected"), None => bail!("not connected"),
}; };
let command_future = add_config( let command_future = add_config(
writer, writer,
self.manifest.clone(), Arc::clone(&self.manifest),
name, name,
data, data,
self.compress, self.compress,
@ -172,15 +172,15 @@ impl BackupTask {
self.check_aborted()?; self.check_aborted()?;
let writer = match self.writer.get() { let writer = match self.writer.get() {
Some(writer) => writer.clone(), Some(writer) => Arc::clone(writer),
None => bail!("not connected"), None => bail!("not connected"),
}; };
let command_future = write_data( let command_future = write_data(
writer, writer,
if self.crypt_mode == CryptMode::Encrypt { self.crypt_config.clone() } else { None }, if self.crypt_mode == CryptMode::Encrypt { self.crypt_config.clone() } else { None },
self.registry.clone(), Arc::clone(&self.registry),
self.known_chunks.clone(), Arc::clone(&self.known_chunks),
dev_id, dev_id,
data, data,
offset, offset,
@ -194,7 +194,7 @@ impl BackupTask {
} }
fn last_manifest(&self) -> Option<Arc<BackupManifest>> { 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( pub fn check_incremental(
@ -204,8 +204,8 @@ impl BackupTask {
) -> bool { ) -> bool {
match self.last_manifest() { match self.last_manifest() {
Some(ref manifest) => { Some(ref manifest) => {
check_last_incremental_csum(manifest.clone(), &device_name, size) check_last_incremental_csum(Arc::clone(manifest), &device_name, size)
&& check_last_encryption_mode(manifest.clone(), &device_name, self.crypt_mode) && check_last_encryption_mode(Arc::clone(manifest), &device_name, self.crypt_mode)
}, },
None => false, None => false,
} }
@ -221,7 +221,7 @@ impl BackupTask {
self.check_aborted()?; self.check_aborted()?;
let writer = match self.writer.get() { let writer = match self.writer.get() {
Some(writer) => writer.clone(), Some(writer) => Arc::clone(writer),
None => bail!("not connected"), None => bail!("not connected"),
}; };
@ -229,9 +229,9 @@ impl BackupTask {
writer, writer,
self.crypt_config.clone(), self.crypt_config.clone(),
self.crypt_mode, self.crypt_mode,
self.last_manifest.get().map(|m| m.clone()), self.last_manifest.get().map(Arc::clone),
self.registry.clone(), Arc::clone(&self.registry),
self.known_chunks.clone(), Arc::clone(&self.known_chunks),
device_name, device_name,
size, size,
self.setup.chunk_size, self.setup.chunk_size,
@ -247,14 +247,14 @@ impl BackupTask {
self.check_aborted()?; self.check_aborted()?;
let writer = match self.writer.get() { let writer = match self.writer.get() {
Some(writer) => writer.clone(), Some(writer) => Arc::clone(writer),
None => bail!("not connected"), None => bail!("not connected"),
}; };
let command_future = close_image( let command_future = close_image(
writer, writer,
self.manifest.clone(), Arc::clone(&self.manifest),
self.registry.clone(), Arc::clone(&self.registry),
dev_id, dev_id,
self.crypt_mode, self.crypt_mode,
); );
@ -268,11 +268,15 @@ impl BackupTask {
self.check_aborted()?; self.check_aborted()?;
let writer = match self.writer.get() { let writer = match self.writer.get() {
Some(writer) => writer.clone(), Some(writer) => Arc::clone(writer),
None => bail!("not connected"), 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(); let mut abort_rx = self.abort.subscribe();
abortable_command(command_future, abort_rx.recv()).await abortable_command(command_future, abort_rx.recv()).await

View File

@ -114,7 +114,7 @@ pub(crate) fn check_last_encryption_mode(
} }
} }
#[allow(clippy::too_many_arguments)]
pub(crate) async fn register_image( pub(crate) async fn register_image(
client: Arc<BackupWriter>, client: Arc<BackupWriter>,
crypt_config: Option<Arc<CryptConfig>>, crypt_config: Option<Arc<CryptConfig>>,
@ -132,7 +132,7 @@ pub(crate) async fn register_image(
let index = match manifest { let index = match manifest {
Some(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), Ok(index) => Some(index),
// not having a previous index is not fatal, so ignore errors // not having a previous index is not fatal, so ignore errors
Err(_) => None 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 wid = client.post("fixed_index", Some(param)).await?.as_u64().unwrap();
let zero_chunk_digest = register_zero_chunk( let zero_chunk_digest = register_zero_chunk(
client.clone(), Arc::clone(&client),
if crypt_mode == CryptMode::Encrypt { crypt_config } else { None }, if crypt_mode == CryptMode::Encrypt { crypt_config } else { None },
chunk_size as usize, chunk_size as usize,
wid, wid,
).await?; ).await?;
let (upload_queue, upload_result) = create_upload_queue( let (upload_queue, upload_result) = create_upload_queue(
client.clone(), Arc::clone(&client),
known_chunks.clone(), Arc::clone(&known_chunks),
initial_index.clone(), Arc::clone(&initial_index),
wid, wid,
device_size, device_size,
chunk_size, chunk_size,

View File

@ -1,3 +1,5 @@
#![warn(clippy::clone_on_ref_ptr)]
use anyhow::{format_err, Error}; use anyhow::{format_err, Error};
use std::ffi::CString; use std::ffi::CString;
use std::ptr; use std::ptr;
@ -152,7 +154,7 @@ impl GotResultCondition {
callback: Self::wakeup_callback, callback: Self::wakeup_callback,
callback_data: (self) as *mut _ as *mut c_void, callback_data: (self) as *mut _ as *mut c_void,
error, 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> { fn backup_handle_to_task(handle: *mut ProxmoxBackupHandle) -> Arc<BackupTask> {
let task = unsafe { & *(handle as *const Arc<BackupTask>) }; let task = unsafe { & *(handle as *const Arc<BackupTask>) };
// increase reference count while we use it inside rust // increase reference count while we use it inside rust
task.clone() Arc::clone(task)
} }
/// Open connection to the backup server (sync) /// Open connection to the backup server (sync)
@ -277,7 +279,7 @@ pub extern "C" fn proxmox_backup_connect(
got_result_condition.wait(); got_result_condition.wait();
return result; result
} }
/// Open connection to the backup server /// 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 task = backup_handle_to_task(handle);
let reason = tools::utf8_c_string_lossy(reason) 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); task.abort(reason);
} }
@ -368,7 +370,7 @@ pub extern "C" fn proxmox_backup_register_image(
got_result_condition.wait(); got_result_condition.wait();
return result; result
} }
/// Register a backup image /// Register a backup image
@ -427,7 +429,7 @@ pub extern "C" fn proxmox_backup_add_config(
got_result_condition.wait(); got_result_condition.wait();
return result; result
} }
/// Add a configuration blob to the backup /// Add a configuration blob to the backup
@ -498,7 +500,7 @@ pub extern "C" fn proxmox_backup_write_data(
got_result_condition.wait(); got_result_condition.wait();
return result; result
} }
/// Write data to into a registered image /// Write data to into a registered image
@ -563,7 +565,7 @@ pub extern "C" fn proxmox_backup_close_image(
got_result_condition.wait(); got_result_condition.wait();
return result; result
} }
/// Close a registered image /// Close a registered image
@ -611,7 +613,7 @@ pub extern "C" fn proxmox_backup_finish(
got_result_condition.wait(); got_result_condition.wait();
return result; result
} }
/// Finish the backup /// 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> { fn restore_handle_to_task(handle: *mut ProxmoxRestoreHandle) -> Arc<RestoreTask> {
let restore_task = unsafe { & *(handle as *const Arc<RestoreTask>) }; let restore_task = unsafe { & *(handle as *const Arc<RestoreTask>) };
// increase reference count while we use it inside rust // increase reference count while we use it inside rust
restore_task.clone() Arc::clone(restore_task)
} }
/// Connect the the backup server for restore (sync) /// Connect the the backup server for restore (sync)
@ -742,7 +744,7 @@ pub extern "C" fn proxmox_restore_connect(
got_result_condition.wait(); got_result_condition.wait();
return result; result
} }
/// Open connection to the backup server (async) /// Open connection to the backup server (async)
/// ///
@ -843,7 +845,7 @@ pub extern "C" fn proxmox_restore_open_image(
got_result_condition.wait(); got_result_condition.wait();
return result; result
} }
/// Retrieve the ID of a handle used to access data in the given archive (async) /// 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(); got_result_condition.wait();
return result; result
} }
/// Read data from the backup image at the given offset (async) /// Read data from the backup image at the given offset (async)

View File

@ -119,12 +119,12 @@ impl RestoreTask {
} }
let client = match self.client.get() { let client = match self.client.get() {
Some(reader) => reader.clone(), Some(reader) => Arc::clone(reader),
None => bail!("not connected"), None => bail!("not connected"),
}; };
let manifest = match self.manifest.get() { let manifest = match self.manifest.get() {
Some(manifest) => manifest.clone(), Some(manifest) => Arc::clone(manifest),
None => bail!("no manifest"), None => bail!("no manifest"),
}; };
@ -141,7 +141,7 @@ impl RestoreTask {
let file_info = manifest.lookup_file_info(&archive_name)?; let file_info = manifest.lookup_file_info(&archive_name)?;
let mut chunk_reader = RemoteChunkReader::new( let mut chunk_reader = RemoteChunkReader::new(
client.clone(), Arc::clone(&client),
self.crypt_config.clone(), self.crypt_config.clone(),
file_info.chunk_crypt_mode(), file_info.chunk_crypt_mode(),
most_used, most_used,
@ -206,12 +206,12 @@ impl RestoreTask {
) -> Result<u8, Error> { ) -> Result<u8, Error> {
let client = match self.client.get() { let client = match self.client.get() {
Some(reader) => reader.clone(), Some(reader) => Arc::clone(reader),
None => bail!("not connected"), None => bail!("not connected"),
}; };
let manifest = match self.manifest.get() { let manifest = match self.manifest.get() {
Some(manifest) => manifest.clone(), Some(manifest) => Arc::clone(manifest),
None => bail!("no manifest"), None => bail!("no manifest"),
}; };
@ -222,7 +222,7 @@ impl RestoreTask {
let file_info = manifest.lookup_file_info(&archive_name)?; let file_info = manifest.lookup_file_info(&archive_name)?;
let chunk_reader = RemoteChunkReader::new( let chunk_reader = RemoteChunkReader::new(
client.clone(), Arc::clone(&client),
self.crypt_config.clone(), self.crypt_config.clone(),
file_info.chunk_crypt_mode(), file_info.chunk_crypt_mode(),
most_used, most_used,
@ -250,7 +250,7 @@ impl RestoreTask {
let (reader, image_size) = { let (reader, image_size) = {
let mut guard = self.image_registry.lock().unwrap(); let mut guard = self.image_registry.lock().unwrap();
let info = guard.lookup(aid)?; let info = guard.lookup(aid)?;
(info.reader.clone(), info.archive_size) (Arc::clone(&info.reader), info.archive_size)
}; };
if offset > image_size { if offset > image_size {

View File

@ -70,6 +70,7 @@ async fn upload_chunk_list(
Ok(()) Ok(())
} }
#[allow(clippy::too_many_arguments)]
async fn upload_handler( async fn upload_handler(
client: Arc<BackupWriter>, client: Arc<BackupWriter>,
known_chunks: Arc<Mutex<HashSet<[u8;32]>>>, known_chunks: Arc<Mutex<HashSet<[u8;32]>>>,
@ -119,7 +120,12 @@ async fn upload_handler(
offset_list.push(offset); offset_list.push(offset);
if digest_list.len() >= 128 { 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)); let _ = upload_result.send(Err(err));
return; return;
} }
@ -133,7 +139,12 @@ async fn upload_handler(
} }
if !digest_list.is_empty() { 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)); let _ = upload_result.send(Err(err));
return; return;
} }