src/config/network.rs: write changes to interfaces.new
This commit is contained in:
		@ -266,19 +266,27 @@ impl NetworkConfig {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub const NETWORK_INTERFACES_FILENAME: &str = "/etc/network/interfaces";
 | 
					pub const NETWORK_INTERFACES_FILENAME: &str = "/etc/network/interfaces";
 | 
				
			||||||
 | 
					pub const NETWORK_INTERFACES_NEW_FILENAME: &str = "/etc/network/interfaces.new";
 | 
				
			||||||
pub const NETWORK_LOCKFILE: &str = "/var/lock/pve-network.lck";
 | 
					pub const NETWORK_LOCKFILE: &str = "/var/lock/pve-network.lck";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn config() -> Result<(NetworkConfig, [u8;32]), Error> {
 | 
					pub fn config() -> Result<(NetworkConfig, [u8;32]), Error> {
 | 
				
			||||||
    let content = match std::fs::read(NETWORK_INTERFACES_FILENAME) {
 | 
					    let content = std::fs::read(NETWORK_INTERFACES_NEW_FILENAME)
 | 
				
			||||||
        Ok(c) => c,
 | 
					        .or_else(|err| {
 | 
				
			||||||
        Err(err) => {
 | 
					 | 
				
			||||||
            if err.kind() == std::io::ErrorKind::NotFound {
 | 
					            if err.kind() == std::io::ErrorKind::NotFound {
 | 
				
			||||||
                Vec::new()
 | 
					                std::fs::read(NETWORK_INTERFACES_FILENAME)
 | 
				
			||||||
 | 
					                    .or_else(|err| {
 | 
				
			||||||
 | 
					                        if err.kind() == std::io::ErrorKind::NotFound {
 | 
				
			||||||
 | 
					                            Ok(Vec::new())
 | 
				
			||||||
 | 
					                        } else {
 | 
				
			||||||
 | 
					                            bail!("unable to read '{}' - {}", NETWORK_INTERFACES_FILENAME, err);
 | 
				
			||||||
 | 
					                         }
 | 
				
			||||||
 | 
					                    })
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                bail!("unable to read '{}' - {}", NETWORK_INTERFACES_FILENAME, err);
 | 
					                bail!("unable to read '{}' - {}", NETWORK_INTERFACES_NEW_FILENAME, err);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        })?;
 | 
				
			||||||
    };
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let digest = openssl::sha::sha256(&content);
 | 
					    let digest = openssl::sha::sha256(&content);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -301,7 +309,7 @@ pub fn save_config(config: &NetworkConfig) -> Result<(), Error> {
 | 
				
			|||||||
        .owner(nix::unistd::ROOT)
 | 
					        .owner(nix::unistd::ROOT)
 | 
				
			||||||
        .group(nix::unistd::Gid::from_raw(0));
 | 
					        .group(nix::unistd::Gid::from_raw(0));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    replace_file(NETWORK_INTERFACES_FILENAME, &raw, options)?;
 | 
					    replace_file(NETWORK_INTERFACES_NEW_FILENAME, &raw, options)?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Ok(())
 | 
					    Ok(())
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user