use proxmox::api::{ApiResponseFuture, ApiHandler, ApiMethod, Router, RpcEnvironment, RpcEnvironmentType};
use proxmox::api::router::SubdirMap;
use proxmox::api::schema::*;
-use proxmox::tools::{try_block, fs::file_get_contents, fs::file_set_contents};
+use proxmox::tools::try_block;
+use proxmox::tools::fs::{file_get_contents, replace_file, CreateOptions};
use crate::api2::types::*;
use crate::backup::*;
// always verify CRC at server side
blob.verify_crc()?;
let raw_data = blob.raw_data();
- file_set_contents(&path, raw_data, None)?;
+ replace_file(&path, raw_data, CreateOptions::new())?;
// fixme: use correct formatter
Ok(crate::server::formatter::json_response(Ok(Value::Null)))
use serde_json::Value;
-use proxmox::tools::{
- digest_to_hex,
- fs::file_set_contents,
-};
+use proxmox::tools::digest_to_hex;
+use proxmox::tools::fs::{replace_file, CreateOptions};
use proxmox::api::{RpcEnvironment, RpcEnvironmentType};
use crate::server::WorkerTask;
blob.verify_crc()?;
let raw_data = blob.raw_data();
- file_set_contents(&path, raw_data, None)?;
+ replace_file(&path, raw_data, CreateOptions::new())?;
self.log(format!("add blob {:?} ({} bytes, comp: {})", path, orig_len, blob_len));
use proxmox::{sortable, identity};
use proxmox::api::{ApiHandler, ApiMethod, Router, RpcEnvironment};
use proxmox::api::schema::*;
-use proxmox::tools::fs::{file_get_contents, file_set_contents};
+use proxmox::tools::fs::{file_get_contents, replace_file, CreateOptions};
use proxmox::tools::*; // required to use IPRE!() macro ???
use crate::api2::types::*;
data.push('\n');
}
- file_set_contents(RESOLV_CONF_FN, data.as_bytes(), None)?;
+ replace_file(RESOLV_CONF_FN, data.as_bytes(), CreateOptions::new())?;
Ok(Value::Null)
}
use proxmox::{sortable, identity};
use proxmox::api::{ApiHandler, ApiMethod, Router, RpcEnvironment};
use proxmox::api::schema::*;
-use proxmox::tools::fs::{file_read_firstline, file_set_contents};
+use proxmox::tools::fs::{file_read_firstline, replace_file, CreateOptions};
use crate::api2::types::*;
bail!("No such timezone.");
}
- file_set_contents("/etc/timezone", timezone.as_bytes(), None)?;
+ replace_file("/etc/timezone", timezone.as_bytes(), CreateOptions::new())?;
let _ = std::fs::remove_file("/etc/localtime");
use proxmox::tools::{
try_block,
- fs::{file_get_contents, file_set_contents, file_set_contents_full},
+ fs::{file_get_contents, replace_file, CreateOptions},
};
fn compute_csrf_secret_digest(
use nix::sys::stat::Mode;
let (_, backup_gid) = crate::tools::getpwnam_ugid("backup")?;
- let uid = Some(nix::unistd::ROOT);
- let gid = Some(nix::unistd::Gid::from_raw(backup_gid));
- file_set_contents_full(
- &path, &pem, Some(Mode::from_bits_truncate(0o0640)), uid, gid)?;
+ replace_file(
+ &path,
+ &pem,
+ CreateOptions::new()
+ .perm(Mode::from_bits_truncate(0o0640))
+ .owner(nix::unistd::ROOT)
+ .group(nix::unistd::Gid::from_raw(backup_gid)),
+ )?;
Ok(())
}
use nix::sys::stat::Mode;
- file_set_contents(
- &priv_path, &priv_pem, Some(Mode::from_bits_truncate(0o0600)))?;
-
+ replace_file(
+ &priv_path, &priv_pem, CreateOptions::new().perm(Mode::from_bits_truncate(0o0600)))?;
let public_pem = rsa.public_key_to_pem()?;
let (_, backup_gid) = crate::tools::getpwnam_ugid("backup")?;
- let uid = Some(nix::unistd::ROOT);
- let gid = Some(nix::unistd::Gid::from_raw(backup_gid));
- file_set_contents_full(
- &public_path, &public_pem, Some(Mode::from_bits_truncate(0o0640)), uid, gid)?;
+ replace_file(
+ &public_path,
+ &public_pem,
+ CreateOptions::new()
+ .perm(Mode::from_bits_truncate(0o0640))
+ .owner(nix::unistd::ROOT)
+ .group(nix::unistd::Gid::from_raw(backup_gid)),
+ )?;
Ok(())
}
use proxmox::tools::{
try_block,
- fs::{file_get_contents, file_set_contents},
+ fs::{file_get_contents, replace_file, CreateOptions},
};
#[derive(Deserialize, Serialize, Debug)]
try_block!({
if replace {
let mode = nix::sys::stat::Mode::S_IRUSR | nix::sys::stat::Mode::S_IWUSR;
- file_set_contents(&path, data.as_bytes(), Some(mode))?;
+ replace_file(&path, data.as_bytes(), CreateOptions::new().perm(mode))?;
} else {
use std::os::unix::fs::OpenOptionsExt;
use std::os::unix::fs::OpenOptionsExt;
use proxmox::{sortable, identity};
-use proxmox::tools::fs::{file_get_contents, file_get_json, file_set_contents, image_size};
+use proxmox::tools::fs::{file_get_contents, file_get_json, replace_file, CreateOptions, image_size};
use proxmox::api::{ApiHandler, ApiMethod, RpcEnvironment};
use proxmox::api::schema::*;
use proxmox::api::cli::*;
let new_data = json!(map);
- let _ = file_set_contents(path, new_data.to_string().as_bytes(), None);
+ let _ = replace_file(path, new_data.to_string().as_bytes(), CreateOptions::new());
}
fn complete_repository(_arg: &str, _param: &HashMap<String, String>) -> Vec<String> {
if server_archive_name == MANIFEST_BLOB_NAME {
let backup_index_data = manifest.into_json().to_string();
if let Some(target) = target {
- file_set_contents(target, backup_index_data.as_bytes(), None)?;
+ replace_file(target, backup_index_data.as_bytes(), CreateOptions::new())?;
} else {
let stdout = std::io::stdout();
let mut writer = stdout.lock();
let target_path = master_pubkey_path()?;
- file_set_contents(&target_path, &pem_data, None)?;
+ replace_file(&target_path, &pem_data, CreateOptions::new())?;
println!("Imported public master key to {:?}", target_path);
let pub_key: Vec<u8> = pkey.public_key_to_pem()?;
let filename_pub = "master-public.pem";
println!("Writing public master key to {}", filename_pub);
- file_set_contents(filename_pub, pub_key.as_slice(), None)?;
+ replace_file(filename_pub, pub_key.as_slice(), CreateOptions::new())?;
let cipher = openssl::symm::Cipher::aes_256_cbc();
let priv_key: Vec<u8> = pkey.private_key_to_pem_pkcs8_passphrase(cipher, new_pw.as_bytes())?;
let filename_priv = "master-private.pem";
println!("Writing private master key to {}", filename_priv);
- file_set_contents(filename_priv, priv_key.as_slice(), None)?;
+ replace_file(filename_priv, priv_key.as_slice(), CreateOptions::new())?;
Ok(Value::Null)
}
use xdg::BaseDirectories;
use proxmox::tools::{
- fs::{file_get_json, file_set_contents},
+ fs::{file_get_json, replace_file, CreateOptions},
};
use super::pipe_to_stream::PipeToSendStream;
map.remove(username);
}
- file_set_contents(path, data.to_string().as_bytes(), Some(mode))?;
+ replace_file(path, data.to_string().as_bytes(), CreateOptions::new().perm(mode))?;
Ok(())
}
}
}
- file_set_contents(path, new_data.to_string().as_bytes(), Some(mode))?;
+ replace_file(path, new_data.to_string().as_bytes(), CreateOptions::new().perm(mode))?;
Ok(())
}
use proxmox::tools::{
try_block,
- fs::{create_path, file_set_contents_full, CreateOptions},
+ fs::{create_path, replace_file, CreateOptions},
};
use super::UPID;
fn update_active_workers(new_upid: Option<&UPID>) -> Result<Vec<TaskListInfo>, Error> {
let (backup_uid, backup_gid) = crate::tools::getpwnam_ugid("backup")?;
- let uid = Some(nix::unistd::Uid::from_raw(backup_uid));
- let gid = Some(nix::unistd::Gid::from_raw(backup_gid));
+ let uid = nix::unistd::Uid::from_raw(backup_uid);
+ let gid = nix::unistd::Gid::from_raw(backup_gid);
let lock = crate::tools::open_file_locked(PROXMOX_BACKUP_TASK_LOCK_FN, std::time::Duration::new(10, 0))?;
- nix::unistd::chown(PROXMOX_BACKUP_TASK_LOCK_FN, uid, gid)?;
+ nix::unistd::chown(PROXMOX_BACKUP_TASK_LOCK_FN, Some(uid), Some(gid))?;
let reader = match File::open(PROXMOX_BACKUP_ACTIVE_TASK_FN) {
Ok(f) => Some(BufReader::new(f)),
}
}
- file_set_contents_full(PROXMOX_BACKUP_ACTIVE_TASK_FN, raw.as_bytes(), None, uid, gid)?;
+ replace_file(
+ PROXMOX_BACKUP_ACTIVE_TASK_FN,
+ raw.as_bytes(),
+ CreateOptions::new()
+ .owner(uid)
+ .group(gid),
+ )?;
drop(lock);