update to nix 0.14, use code from proxmox:tools
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
use failure::*;
|
||||
|
||||
|
||||
use crate::tools;
|
||||
use proxmox::tools::fs::{file_get_contents, file_set_contents};
|
||||
use crate::api2::*;
|
||||
use crate::api_schema::*;
|
||||
//use crate::api_schema::router::*;
|
||||
@ -23,7 +22,7 @@ fn read_etc_resolv_conf() -> Result<Value, Error> {
|
||||
|
||||
let mut nscount = 0;
|
||||
|
||||
let raw = tools::file_get_contents(RESOLV_CONF_FN)?;
|
||||
let raw = file_get_contents(RESOLV_CONF_FN)?;
|
||||
|
||||
result["digest"] = Value::from(proxmox::tools::digest_to_hex(&sha::sha256(&raw)));
|
||||
|
||||
@ -63,13 +62,13 @@ fn update_dns(
|
||||
|
||||
let _guard = MUTEX.lock();
|
||||
|
||||
let search = tools::required_string_param(¶m, "search")?;
|
||||
let search = crate::tools::required_string_param(¶m, "search")?;
|
||||
|
||||
let raw = tools::file_get_contents(RESOLV_CONF_FN)?;
|
||||
let raw = file_get_contents(RESOLV_CONF_FN)?;
|
||||
let old_digest = proxmox::tools::digest_to_hex(&sha::sha256(&raw));
|
||||
|
||||
if let Some(digest) = param["digest"].as_str() {
|
||||
tools::assert_if_modified(&old_digest, &digest)?;
|
||||
crate::tools::assert_if_modified(&old_digest, &digest)?;
|
||||
}
|
||||
|
||||
let old_data = String::from_utf8(raw)?;
|
||||
@ -92,7 +91,7 @@ fn update_dns(
|
||||
data.push('\n');
|
||||
}
|
||||
|
||||
tools::file_set_contents(RESOLV_CONF_FN, data.as_bytes(), None)?;
|
||||
file_set_contents(RESOLV_CONF_FN, data.as_bytes(), None)?;
|
||||
|
||||
Ok(Value::Null)
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use failure::*;
|
||||
use proxmox::tools::fs::{file_read_firstline, file_set_contents};
|
||||
|
||||
use crate::tools;
|
||||
use crate::api_schema::*;
|
||||
use crate::api_schema::router::*;
|
||||
use crate::api2::types::*;
|
||||
@ -11,7 +11,7 @@ use chrono::prelude::*;
|
||||
|
||||
fn read_etc_localtime() -> Result<String, Error> {
|
||||
// use /etc/timezone
|
||||
if let Ok(line) = tools::file_read_firstline("/etc/timezone") {
|
||||
if let Ok(line) = file_read_firstline("/etc/timezone") {
|
||||
return Ok(line.trim().to_owned());
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ fn set_timezone(
|
||||
_rpcenv: &mut dyn RpcEnvironment,
|
||||
) -> Result<Value, Error> {
|
||||
|
||||
let timezone = tools::required_string_param(¶m, "timezone")?;
|
||||
let timezone = crate::tools::required_string_param(¶m, "timezone")?;
|
||||
|
||||
let path = std::path::PathBuf::from(format!("/usr/share/zoneinfo/{}", timezone));
|
||||
|
||||
@ -64,7 +64,7 @@ fn set_timezone(
|
||||
bail!("No such timezone.");
|
||||
}
|
||||
|
||||
tools::file_set_contents("/etc/timezone", timezone.as_bytes(), None)?;
|
||||
file_set_contents("/etc/timezone", timezone.as_bytes(), None)?;
|
||||
|
||||
let _ = std::fs::remove_file("/etc/localtime");
|
||||
|
||||
|
Reference in New Issue
Block a user