Fix next_nth sorting bug

This commit is contained in:
Garrett Mills 2025-02-24 22:34:02 -05:00
parent 27c2d38fe1
commit 0359de37c8
2 changed files with 17 additions and 12 deletions

View File

@ -455,7 +455,9 @@ async fn transfer_directly(
let storage = &svc.config.pve_storage_pool; let storage = &svc.config.pve_storage_pool;
let name_offset = storage.len() + 1; // 1 for the colon (:) let name_offset = storage.len() + 1; // 1 for the colon (:)
let disk_name = mount[name_offset..].split(",").next().unwrap(); let disk_name = mount[name_offset..].split(",").next().unwrap();
debug!("transfer_directly: mount {mount} | name_offset {name_offset} | disk_name {disk_name}"); debug!("transfer_directly: mount {mount} | name_offset {name_offset} | disk_name {disk_name}");
// Persist the volume // Persist the volume
let mut vol = vol.into_active_model(); let mut vol = vol.into_active_model();
vol.pve_node_id = Set(to_node.pve_id); vol.pve_node_id = Set(to_node.pve_id);

View File

@ -96,6 +96,7 @@ pub async fn try_lock_first_available<'a>(
/** The PVE config file for an LXC container (i.e. /etc/pve/lxc/XYZ.conf) */ /** The PVE config file for an LXC container (i.e. /etc/pve/lxc/XYZ.conf) */
#[derive(Debug)]
pub struct PveConfig { pub struct PveConfig {
lines: Vec<String>, lines: Vec<String>,
} }
@ -167,19 +168,21 @@ impl PveConfig {
* Using that example, next_nth("volume") would return 2. * Using that example, next_nth("volume") would return 2.
*/ */
pub fn next_nth(&self, prefix: &str) -> u32 { pub fn next_nth(&self, prefix: &str) -> u32 {
let res = self.lines let mut res = self.lines // list of lines
.iter() .iter() // as an iterator
.filter(|line| line.starts_with(prefix)) .filter(|line| line.starts_with(prefix)) // only lines starting with "mp"
.map(|line| .map(|line|
line[prefix.len()..] line[prefix.len()..] // string after the prefix ("1: <fubar>")
.split(":") .split(":") // ["1", " <fubar>"]
.next() .next() // "1"
.unwrap() .unwrap() // "1"
.parse::<u32>()) .parse::<u32>()) // 1
.filter_map(|idx| idx.ok()) .filter_map(|idx| idx.ok()) // [1, 2]
.next(); .collect::<Vec<u32>>(); // [1, 2]
if let Some(idx) = res { res.sort_by(|a, z| z.cmp(a)); // [2, 1]
if let Some(idx) = res.first() {
return idx + 1; return idx + 1;
} }