5
0
mirror of git://git.proxmox.com/git/proxmox-backup.git synced 2025-02-25 17:57:35 +03:00

clippy fixes

and one additional API fn "allow many parameters" addition.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2022-10-11 09:26:32 +02:00
parent c36c901172
commit f097eaa80f
9 changed files with 112 additions and 142 deletions

View File

@ -246,7 +246,7 @@ fn test_human_byte_parser() -> Result<(), Error> {
} }
let new = h.to_string(); let new = h.to_string();
if &new != as_str { if new != *as_str {
bail!("to_string failed for '{}' ({:?} != {:?})", v, new, as_str); bail!("to_string failed for '{}' ({:?} != {:?})", v, new, as_str);
} }
Ok(()) Ok(())

View File

@ -391,6 +391,7 @@ async fn list(
} }
)] )]
/// Restore files from a backup snapshot. /// Restore files from a backup snapshot.
#[allow(clippy::too_many_arguments)]
async fn extract( async fn extract(
ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
snapshot: String, snapshot: String,

View File

@ -490,7 +490,7 @@ unsafe fn list_snapshots_blocking(
.filter_map(|backup_type| { .filter_map(|backup_type| {
let group = let group =
datastore.backup_group_from_parts(ns.clone(), backup_type, backup_id.clone()); datastore.backup_group_from_parts(ns.clone(), backup_type, backup_id.clone());
group.exists().then(move || group) group.exists().then_some(group)
}) })
.collect(), .collect(),
// FIXME: Recursion // FIXME: Recursion

View File

@ -511,51 +511,43 @@ acl:1:/remote/remote1/remotestore1:write@pbs:RemoteSyncOperator
}; };
// should work without ACLs // should work without ACLs
assert_eq!( assert!(
check_sync_job_read_access(&user_info, root_auth_id, &job), check_sync_job_read_access(&user_info, root_auth_id, &job)
true
); );
assert_eq!( assert!(
check_sync_job_modify_access(&user_info, root_auth_id, &job), check_sync_job_modify_access(&user_info, root_auth_id, &job)
true
); );
// user without permissions must fail // user without permissions must fail
assert_eq!( assert!(
check_sync_job_read_access(&user_info, &no_perm_auth_id, &job), !check_sync_job_read_access(&user_info, &no_perm_auth_id, &job)
false
); );
assert_eq!( assert!(
check_sync_job_modify_access(&user_info, &no_perm_auth_id, &job), !check_sync_job_modify_access(&user_info, &no_perm_auth_id, &job)
false
); );
// reading without proper read permissions on either remote or local must fail // reading without proper read permissions on either remote or local must fail
assert_eq!( assert!(
check_sync_job_read_access(&user_info, &read_auth_id, &job), !check_sync_job_read_access(&user_info, &read_auth_id, &job)
false
); );
// reading without proper read permissions on local end must fail // reading without proper read permissions on local end must fail
job.remote = "remote1".to_string(); job.remote = "remote1".to_string();
assert_eq!( assert!(
check_sync_job_read_access(&user_info, &read_auth_id, &job), !check_sync_job_read_access(&user_info, &read_auth_id, &job)
false
); );
// reading without proper read permissions on remote end must fail // reading without proper read permissions on remote end must fail
job.remote = "remote0".to_string(); job.remote = "remote0".to_string();
job.store = "localstore1".to_string(); job.store = "localstore1".to_string();
assert_eq!( assert!(
check_sync_job_read_access(&user_info, &read_auth_id, &job), !check_sync_job_read_access(&user_info, &read_auth_id, &job)
false
); );
// writing without proper write permissions on either end must fail // writing without proper write permissions on either end must fail
job.store = "localstore0".to_string(); job.store = "localstore0".to_string();
assert_eq!( assert!(
check_sync_job_modify_access(&user_info, &write_auth_id, &job), !check_sync_job_modify_access(&user_info, &write_auth_id, &job)
false
); );
// writing without proper write permissions on local end must fail // writing without proper write permissions on local end must fail
@ -564,84 +556,71 @@ acl:1:/remote/remote1/remotestore1:write@pbs:RemoteSyncOperator
// writing without proper write permissions on remote end must fail // writing without proper write permissions on remote end must fail
job.remote = "remote0".to_string(); job.remote = "remote0".to_string();
job.store = "localstore1".to_string(); job.store = "localstore1".to_string();
assert_eq!( assert!(
check_sync_job_modify_access(&user_info, &write_auth_id, &job), !check_sync_job_modify_access(&user_info, &write_auth_id, &job)
false
); );
// reset remote to one where users have access // reset remote to one where users have access
job.remote = "remote1".to_string(); job.remote = "remote1".to_string();
// user with read permission can only read, but not modify/run // user with read permission can only read, but not modify/run
assert_eq!( assert!(
check_sync_job_read_access(&user_info, &read_auth_id, &job), check_sync_job_read_access(&user_info, &read_auth_id, &job)
true
); );
job.owner = Some(read_auth_id.clone()); job.owner = Some(read_auth_id.clone());
assert_eq!( assert!(
check_sync_job_modify_access(&user_info, &read_auth_id, &job), !check_sync_job_modify_access(&user_info, &read_auth_id, &job)
false
); );
job.owner = None; job.owner = None;
assert_eq!( assert!(
check_sync_job_modify_access(&user_info, &read_auth_id, &job), !check_sync_job_modify_access(&user_info, &read_auth_id, &job)
false
); );
job.owner = Some(write_auth_id.clone()); job.owner = Some(write_auth_id.clone());
assert_eq!( assert!(
check_sync_job_modify_access(&user_info, &read_auth_id, &job), !check_sync_job_modify_access(&user_info, &read_auth_id, &job)
false
); );
// user with simple write permission can modify/run // user with simple write permission can modify/run
assert_eq!( assert!(
check_sync_job_read_access(&user_info, &write_auth_id, &job), check_sync_job_read_access(&user_info, &write_auth_id, &job)
true
); );
assert_eq!( assert!(
check_sync_job_modify_access(&user_info, &write_auth_id, &job), check_sync_job_modify_access(&user_info, &write_auth_id, &job)
true
); );
// but can't modify/run with deletion // but can't modify/run with deletion
job.remove_vanished = Some(true); job.remove_vanished = Some(true);
assert_eq!( assert!(
check_sync_job_modify_access(&user_info, &write_auth_id, &job), !check_sync_job_modify_access(&user_info, &write_auth_id, &job)
false
); );
// unless they have Datastore.Prune as well // unless they have Datastore.Prune as well
job.store = "localstore2".to_string(); job.store = "localstore2".to_string();
assert_eq!( assert!(
check_sync_job_modify_access(&user_info, &write_auth_id, &job), check_sync_job_modify_access(&user_info, &write_auth_id, &job)
true
); );
// changing owner is not possible // changing owner is not possible
job.owner = Some(read_auth_id.clone()); job.owner = Some(read_auth_id.clone());
assert_eq!( assert!(
check_sync_job_modify_access(&user_info, &write_auth_id, &job), !check_sync_job_modify_access(&user_info, &write_auth_id, &job)
false
); );
// also not to the default 'root@pam' // also not to the default 'root@pam'
job.owner = None; job.owner = None;
assert_eq!( assert!(
check_sync_job_modify_access(&user_info, &write_auth_id, &job), !check_sync_job_modify_access(&user_info, &write_auth_id, &job)
false
); );
// unless they have Datastore.Modify as well // unless they have Datastore.Modify as well
job.store = "localstore3".to_string(); job.store = "localstore3".to_string();
job.owner = Some(read_auth_id); job.owner = Some(read_auth_id);
assert_eq!( assert!(
check_sync_job_modify_access(&user_info, &write_auth_id, &job), check_sync_job_modify_access(&user_info, &write_auth_id, &job)
true
); );
job.owner = None; job.owner = None;
assert_eq!( assert!(
check_sync_job_modify_access(&user_info, &write_auth_id, &job), check_sync_job_modify_access(&user_info, &write_auth_id, &job)
true
); );
Ok(()) Ok(())

View File

@ -420,7 +420,7 @@ pub fn send_prune_status(
jobname: &str, jobname: &str,
result: &Result<(), Error>, result: &Result<(), Error>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let (email, notify) = match lookup_datastore_notify_settings(&store) { let (email, notify) = match lookup_datastore_notify_settings(store) {
(Some(email), notify) => (email, notify), (Some(email), notify) => (email, notify),
(None, _) => return Ok(()), (None, _) => return Ok(()),
}; };

View File

@ -118,46 +118,36 @@ fn test_media_expire_time() -> Result<(), Error> {
&MediaStatus::Writable &MediaStatus::Writable
); );
assert_eq!( assert!(
pool.media_is_expired(&pool.lookup_media(&tape0_uuid)?, 0), !pool.media_is_expired(&pool.lookup_media(&tape0_uuid)?, 0)
false
); );
assert_eq!( assert!(
pool.media_is_expired(&pool.lookup_media(&tape0_uuid)?, 60), !pool.media_is_expired(&pool.lookup_media(&tape0_uuid)?, 60)
false
); );
assert_eq!( assert!(
pool.media_is_expired(&pool.lookup_media(&tape0_uuid)?, 120), !pool.media_is_expired(&pool.lookup_media(&tape0_uuid)?, 120)
false
); );
assert_eq!( assert!(
pool.media_is_expired(&pool.lookup_media(&tape0_uuid)?, 180), pool.media_is_expired(&pool.lookup_media(&tape0_uuid)?, 180)
true
); );
assert_eq!( assert!(
pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 0), !pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 0)
false
); );
assert_eq!( assert!(
pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 60), !pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 60)
false
); );
assert_eq!( assert!(
pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 120), !pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 120)
false
); );
assert_eq!( assert!(
pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 180), !pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 180)
false
); );
assert_eq!( assert!(
pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 190), !pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 190)
false
); );
assert_eq!( assert!(
pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 240), pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 240)
true
); );
Ok(()) Ok(())

View File

@ -38,7 +38,7 @@ fn test_current_set_usable_1() -> Result<(), Error> {
false, false,
)?; )?;
assert_eq!(pool.current_set_usable()?, false); assert!(!pool.current_set_usable()?);
Ok(()) Ok(())
} }
@ -64,7 +64,7 @@ fn test_current_set_usable_2() -> Result<(), Error> {
false, false,
)?; )?;
assert_eq!(pool.current_set_usable()?, false); assert!(!pool.current_set_usable()?);
Ok(()) Ok(())
} }
@ -92,7 +92,7 @@ fn test_current_set_usable_3() -> Result<(), Error> {
false, false,
)?; )?;
assert_eq!(pool.current_set_usable()?, false); assert!(!pool.current_set_usable()?);
Ok(()) Ok(())
} }
@ -120,7 +120,7 @@ fn test_current_set_usable_4() -> Result<(), Error> {
false, false,
)?; )?;
assert_eq!(pool.current_set_usable()?, true); assert!(pool.current_set_usable()?);
Ok(()) Ok(())
} }
@ -150,7 +150,7 @@ fn test_current_set_usable_5() -> Result<(), Error> {
false, false,
)?; )?;
assert_eq!(pool.current_set_usable()?, true); assert!(pool.current_set_usable()?);
Ok(()) Ok(())
} }

View File

@ -94,13 +94,13 @@ fn test_list_pool_media() -> Result<(), Error> {
let tape2 = list let tape2 = list
.iter() .iter()
.find(|media_id| &media_id.label.uuid == &tape2_uuid) .find(|media_id| media_id.label.uuid == tape2_uuid)
.unwrap(); .unwrap();
assert!(tape2.media_set_label.is_none()); assert!(tape2.media_set_label.is_none());
let tape3 = list let tape3 = list
.iter() .iter()
.find(|media_id| &media_id.label.uuid == &tape3_uuid) .find(|media_id| media_id.label.uuid == tape3_uuid)
.unwrap(); .unwrap();
match tape3.media_set_label { match tape3.media_set_label {
None => bail!("missing media set label"), None => bail!("missing media set label"),

View File

@ -52,18 +52,18 @@ fn create_info_protected(snapshot: &str, partial: bool) -> BackupInfo {
#[test] #[test]
fn test_prune_protected() -> Result<(), Error> { fn test_prune_protected() -> Result<(), Error> {
let mut orig_list = Vec::new(); let orig_list = vec![
create_info_protected(
orig_list.push(create_info_protected( "host/elsa/2019-11-15T09:39:15Z",
"host/elsa/2019-11-15T09:39:15Z", false,
false, ),
)); create_info("host/elsa/2019-11-15T10:39:15Z", false),
orig_list.push(create_info("host/elsa/2019-11-15T10:39:15Z", false)); create_info("host/elsa/2019-11-15T10:49:15Z", false),
orig_list.push(create_info("host/elsa/2019-11-15T10:49:15Z", false)); create_info_protected(
orig_list.push(create_info_protected( "host/elsa/2019-11-15T10:59:15Z",
"host/elsa/2019-11-15T10:59:15Z", false,
false, ),
)); ];
eprintln!("{:?}", orig_list); eprintln!("{:?}", orig_list);
@ -75,7 +75,7 @@ fn test_prune_protected() -> Result<(), Error> {
let mut options = PruneJobOptions::default(); let mut options = PruneJobOptions::default();
options.keep.keep_hourly = Some(1); options.keep.keep_hourly = Some(1);
let remove_list = get_prune_list(orig_list.clone(), false, &options); let remove_list = get_prune_list(orig_list, false, &options);
let expect: Vec<PathBuf> = vec![PathBuf::from("host/elsa/2019-11-15T10:39:15Z")]; let expect: Vec<PathBuf> = vec![PathBuf::from("host/elsa/2019-11-15T10:39:15Z")];
assert_eq!(remove_list, expect); assert_eq!(remove_list, expect);
Ok(()) Ok(())
@ -83,14 +83,14 @@ fn test_prune_protected() -> Result<(), Error> {
#[test] #[test]
fn test_prune_hourly() -> Result<(), Error> { fn test_prune_hourly() -> Result<(), Error> {
let mut orig_list = Vec::new(); let orig_list = vec![
create_info("host/elsa/2019-11-15T09:39:15Z", false),
orig_list.push(create_info("host/elsa/2019-11-15T09:39:15Z", false)); create_info("host/elsa/2019-11-15T10:49:15Z", false),
orig_list.push(create_info("host/elsa/2019-11-15T10:49:15Z", false)); create_info("host/elsa/2019-11-15T10:59:15Z", false),
orig_list.push(create_info("host/elsa/2019-11-15T10:59:15Z", false)); create_info("host/elsa/2019-11-15T11:39:15Z", false),
orig_list.push(create_info("host/elsa/2019-11-15T11:39:15Z", false)); create_info("host/elsa/2019-11-15T11:49:15Z", false),
orig_list.push(create_info("host/elsa/2019-11-15T11:49:15Z", false)); create_info("host/elsa/2019-11-15T11:59:15Z", false),
orig_list.push(create_info("host/elsa/2019-11-15T11:59:15Z", false)); ];
let list = orig_list.clone(); let list = orig_list.clone();
let mut options = PruneJobOptions::default(); let mut options = PruneJobOptions::default();
@ -118,17 +118,17 @@ fn test_prune_hourly() -> Result<(), Error> {
#[test] #[test]
fn test_prune_simple2() -> Result<(), Error> { fn test_prune_simple2() -> Result<(), Error> {
let mut orig_list = Vec::new(); let orig_list = vec![
create_info("host/elsa/2018-11-15T11:59:15Z", false),
orig_list.push(create_info("host/elsa/2018-11-15T11:59:15Z", false)); create_info("host/elsa/2019-11-15T11:59:15Z", false),
orig_list.push(create_info("host/elsa/2019-11-15T11:59:15Z", false)); create_info("host/elsa/2019-11-21T11:59:15Z", false),
orig_list.push(create_info("host/elsa/2019-11-21T11:59:15Z", false)); create_info("host/elsa/2019-11-22T11:59:15Z", false),
orig_list.push(create_info("host/elsa/2019-11-22T11:59:15Z", false)); create_info("host/elsa/2019-11-29T11:59:15Z", false),
orig_list.push(create_info("host/elsa/2019-11-29T11:59:15Z", false)); create_info("host/elsa/2019-12-01T11:59:15Z", false),
orig_list.push(create_info("host/elsa/2019-12-01T11:59:15Z", false)); create_info("host/elsa/2019-12-02T11:59:15Z", false),
orig_list.push(create_info("host/elsa/2019-12-02T11:59:15Z", false)); create_info("host/elsa/2019-12-03T11:59:15Z", false),
orig_list.push(create_info("host/elsa/2019-12-03T11:59:15Z", false)); create_info("host/elsa/2019-12-04T11:59:15Z", false),
orig_list.push(create_info("host/elsa/2019-12-04T11:59:15Z", false)); ];
let list = orig_list.clone(); let list = orig_list.clone();
let mut options = PruneJobOptions::default(); let mut options = PruneJobOptions::default();
@ -188,13 +188,13 @@ fn test_prune_simple2() -> Result<(), Error> {
#[test] #[test]
fn test_prune_simple() -> Result<(), Error> { fn test_prune_simple() -> Result<(), Error> {
let mut orig_list = Vec::new(); let orig_list = vec![
create_info("host/elsa/2019-12-02T11:59:15Z", false),
orig_list.push(create_info("host/elsa/2019-12-02T11:59:15Z", false)); create_info("host/elsa/2019-12-03T11:59:15Z", false),
orig_list.push(create_info("host/elsa/2019-12-03T11:59:15Z", false)); create_info("host/elsa/2019-12-04T11:59:15Z", false),
orig_list.push(create_info("host/elsa/2019-12-04T11:59:15Z", false)); create_info("host/elsa/2019-12-04T12:59:15Z", false),
orig_list.push(create_info("host/elsa/2019-12-04T12:59:15Z", false)); ];
// keep-last tests // keep-last tests
let list = orig_list.clone(); let list = orig_list.clone();