[pbs-devel] [PATCH proxmox-backup 2/6] api2/node/tasks: change limit behaviour when it is 0
Dominik Csapak
d.csapak at proxmox.com
Fri Oct 30 15:02:11 CET 2020
instead of returning 0 elements (which does not really make sense anyway),
change it so that there is no limit anymore (besides usize::MAX)
this is technically a breaking change for the api, but i guess
no one is using limit=0 for anything sensible anyway
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/api2/node/tasks.rs | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/api2/node/tasks.rs b/src/api2/node/tasks.rs
index 9146d351..00516f3b 100644
--- a/src/api2/node/tasks.rs
+++ b/src/api2/node/tasks.rs
@@ -271,7 +271,7 @@ fn stop_task(
},
limit: {
type: u64,
- description: "Only list this amount of tasks.",
+ description: "Only list this amount of tasks. (0 means no limit)",
default: 50,
optional: true,
},
@@ -328,6 +328,7 @@ pub fn list_tasks(
let store = param["store"].as_str();
let list = TaskListInfoIterator::new(running)?;
+ let limit = if limit > 0 { limit as usize } else { usize::MAX };
let result: Vec<TaskListItem> = list
.take_while(|info| !info.is_err())
@@ -372,11 +373,11 @@ pub fn list_tasks(
Some(info.into())
}).skip(start as usize)
- .take(limit as usize)
+ .take(limit)
.collect();
let mut count = result.len() + start as usize;
- if result.len() > 0 && result.len() >= limit as usize { // we have a 'virtual' entry as long as we have any new
+ if result.len() > 0 && result.len() >= limit { // we have a 'virtual' entry as long as we have any new
count += 1;
}
--
2.20.1
More information about the pbs-devel
mailing list