Skip to content

Commit

Permalink
proxmoxve: don't read user-data file twice when checking header
Browse files Browse the repository at this point in the history
  • Loading branch information
arcln committed Jun 13, 2024
1 parent d480893 commit 668bbe3
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/providers/proxmoxve/cloudconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use slog_scope::warn;
use std::{
collections::HashMap,
fs::File,
io::{BufRead, BufReader},
net::{AddrParseError, IpAddr},
path::Path,
str::FromStr,
Expand Down Expand Up @@ -82,14 +81,12 @@ pub struct ProxmoxVECloudNetworkConfigSubnet {

impl ProxmoxVECloudConfig {
pub fn try_new(path: &Path) -> Result<Self> {
let user_data_file = BufReader::new(File::open(path.join("user-data"))?);
let mut user_data = None;
let raw_user_data = std::fs::read_to_string(path.join("user-data"))?;

if let Some(first_line) = user_data_file.lines().next() {
if let Ok(first_line) = first_line {
if first_line.starts_with("#cloud-config") {
user_data = serde_yaml::from_reader(File::open(path.join("user-data"))?)?;
}
if let Some(first_line) = raw_user_data.split('\n').next() {
if first_line.starts_with("#cloud-config") {
user_data = serde_yaml::from_str(&raw_user_data)?;
}
}

Expand Down

0 comments on commit 668bbe3

Please sign in to comment.