If a node never has had any guests on it, the pve2-vm directory does not exist yet, which led to a failure when attempting to read the contents of this directory. This is fixed by explicitly checking for a 'not found' error (we still want to fail for other kinds of errors).
Signed-off-by: Lukas Wagner <l.wag...@proxmox.com> --- src/main.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 6fcdc10..fb58d3a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use anyhow::{bail, Error, Result}; use std::{ ffi::{CStr, CString, OsString}, fs, + io::ErrorKind, os::unix::{ffi::OsStrExt, fs::PermissionsExt}, path::{Path, PathBuf}, sync::Arc, @@ -319,7 +320,15 @@ fn mv_old(file: &str) -> Result<()> { fn collect_rrd_files(location: &PathBuf) -> Result<Vec<(CString, OsString)>> { let mut files: Vec<(CString, OsString)> = Vec::new(); - fs::read_dir(location)? + let contents = match fs::read_dir(location) { + Ok(contents) => contents, + Err(e) if e.kind() == ErrorKind::NotFound => { + return Ok(files); + } + Err(e) => return Err(e.into()), + }; + + contents .filter(|f| f.is_ok()) .map(|f| f.unwrap().path()) .filter(|f| f.is_file() && f.extension().is_none()) @@ -409,6 +418,11 @@ fn migrate_guests( let guest_source_files = collect_rrd_files(&source_dir_guests)?; + if guest_source_files.is_empty() { + println!("No guest metrics to migrate"); + return Ok(()); + } + if !target_dir_guests.exists() && migrate { println!("Creating new directory: '{}'", target_dir_guests.display()); std::fs::create_dir(&target_dir_guests)?; -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel