From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id D45121FF2F6 for ; Wed, 29 May 2024 11:39:49 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CD8C51CE0; Wed, 29 May 2024 11:40:13 +0200 (CEST) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com Date: Wed, 29 May 2024 11:39:56 +0200 Message-Id: <20240529093956.933849-1-dietmar@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.544 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [daemon.rs, lib.rs, file.rs, logrotate.rs, journal.rs, files.rs, dir.rs, cache.rs, rrd.rs] Subject: [pbs-devel] [PATCH proxmox] sys: pass create options as reference X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Signed-off-by: Dietmar Maurer --- proxmox-openid/src/auth_state.rs | 4 ++-- proxmox-rest-server/src/api_config.rs | 4 ++-- proxmox-rest-server/src/daemon.rs | 2 +- proxmox-rest-server/src/file_logger.rs | 2 +- proxmox-rest-server/src/lib.rs | 2 +- proxmox-rest-server/src/worker_task.rs | 10 +++++----- proxmox-rrd/src/cache.rs | 4 ++-- proxmox-rrd/src/cache/journal.rs | 4 ++-- proxmox-rrd/src/cache/rrd_map.rs | 4 ++-- proxmox-rrd/src/rrd.rs | 2 +- proxmox-subscription/src/files.rs | 4 ++-- proxmox-sys/src/fs/dir.rs | 20 ++++++++++---------- proxmox-sys/src/fs/file.rs | 8 ++++---- proxmox-sys/src/logrotate.rs | 2 +- 14 files changed, 36 insertions(+), 36 deletions(-) diff --git a/proxmox-openid/src/auth_state.rs b/proxmox-openid/src/auth_state.rs index f2a299a0..72b7ce4c 100644 --- a/proxmox-openid/src/auth_state.rs +++ b/proxmox-openid/src/auth_state.rs @@ -20,7 +20,7 @@ fn load_auth_state_locked( lock_path, std::time::Duration::new(10, 0), true, - CreateOptions::new(), + &CreateOptions::new(), )?; let mut path = state_dir.to_owned(); @@ -50,7 +50,7 @@ fn replace_auth_state(path: &Path, data: &Vec) -> Result<(), Error> { let options = CreateOptions::new().perm(mode); let raw = serde_json::to_string_pretty(data)?; - replace_file(path, raw.as_bytes(), options, false)?; + replace_file(path, raw.as_bytes(), &options, false)?; Ok(()) } diff --git a/proxmox-rest-server/src/api_config.rs b/proxmox-rest-server/src/api_config.rs index 80589446..1ab2130e 100644 --- a/proxmox-rest-server/src/api_config.rs +++ b/proxmox-rest-server/src/api_config.rs @@ -213,7 +213,7 @@ impl ApiConfig { let path: PathBuf = path.into(); if let Some(base) = path.parent() { if !base.exists() { - create_path(base, None, dir_opts).map_err(|err| format_err!("{}", err))?; + create_path(base, None, dir_opts.as_ref()).map_err(|err| format_err!("{}", err))?; } } @@ -252,7 +252,7 @@ impl ApiConfig { let path: PathBuf = path.into(); if let Some(base) = path.parent() { if !base.exists() { - create_path(base, None, dir_opts).map_err(|err| format_err!("{}", err))?; + create_path(base, None, dir_opts.as_ref()).map_err(|err| format_err!("{}", err))?; } } diff --git a/proxmox-rest-server/src/daemon.rs b/proxmox-rest-server/src/daemon.rs index fedbf545..098b93f0 100644 --- a/proxmox-rest-server/src/daemon.rs +++ b/proxmox-rest-server/src/daemon.rs @@ -186,7 +186,7 @@ impl Reloader { proxmox_sys::fs::replace_file( pid_fn, pid_str.as_bytes(), - CreateOptions::new(), + &CreateOptions::new(), false, )?; } diff --git a/proxmox-rest-server/src/file_logger.rs b/proxmox-rest-server/src/file_logger.rs index 2bb1fac6..50a23a02 100644 --- a/proxmox-rest-server/src/file_logger.rs +++ b/proxmox-rest-server/src/file_logger.rs @@ -98,7 +98,7 @@ impl FileLogger { } let file = - atomic_open_or_create_file(&file_name, flags, &[], options.file_opts.clone(), false)?; + atomic_open_or_create_file(&file_name, flags, &[], &options.file_opts, false)?; Ok(file) } diff --git a/proxmox-rest-server/src/lib.rs b/proxmox-rest-server/src/lib.rs index ce9e4f15..ac0cc4ce 100644 --- a/proxmox-rest-server/src/lib.rs +++ b/proxmox-rest-server/src/lib.rs @@ -80,7 +80,7 @@ pub(crate) fn pstart() -> u64 { /// Helper to write the PID into a file pub fn write_pid(pid_fn: &str) -> Result<(), Error> { let pid_str = format!("{}\n", *PID); - proxmox_sys::fs::replace_file(pid_fn, pid_str.as_bytes(), CreateOptions::new(), false) + proxmox_sys::fs::replace_file(pid_fn, pid_str.as_bytes(), &CreateOptions::new(), false) } /// Helper to read the PID from a file diff --git a/proxmox-rest-server/src/worker_task.rs b/proxmox-rest-server/src/worker_task.rs index 4cf24cc4..b63f7049 100644 --- a/proxmox-rest-server/src/worker_task.rs +++ b/proxmox-rest-server/src/worker_task.rs @@ -83,7 +83,7 @@ impl WorkerTaskSetup { let timeout = std::time::Duration::new(10, 0); let file = - proxmox_sys::fs::open_file_locked(&self.task_lock_fn, timeout, exclusive, options)?; + proxmox_sys::fs::open_file_locked(&self.task_lock_fn, timeout, exclusive, &options)?; Ok(TaskListLockGuard(file)) } @@ -107,7 +107,7 @@ impl WorkerTaskSetup { .clone() .perm(nix::sys::stat::Mode::from_bits_truncate(0o755)); - create_path(&path, None, Some(dir_opts))?; + create_path(&path, None, Some(&dir_opts))?; path.push(upid.to_string()); Ok(path) @@ -166,7 +166,7 @@ impl WorkerTaskSetup { .clone() .perm(nix::sys::stat::Mode::from_bits_truncate(0o660)); - replace_file(&self.active_tasks_fn, active_raw.as_bytes(), options, false)?; + replace_file(&self.active_tasks_fn, active_raw.as_bytes(), &options, false)?; finish_list.sort_unstable_by(|a, b| match (&a.state, &b.state) { (Some(s1), Some(s2)) => s1.cmp(s2), @@ -185,7 +185,7 @@ impl WorkerTaskSetup { &self.task_archive_fn, OFlag::O_APPEND | OFlag::O_RDWR, &[], - options, + &options, false, )?; for info in &finish_list { @@ -212,7 +212,7 @@ impl WorkerTaskSetup { .clone() .perm(nix::sys::stat::Mode::from_bits_truncate(0o755)); - create_path(&self.taskdir, Some(dir_opts.clone()), Some(dir_opts))?; + create_path(&self.taskdir, Some(&dir_opts), Some(&dir_opts))?; // fixme:??? create_path(pbs_buildcfg::PROXMOX_BACKUP_RUN_DIR, None, Some(opts))?; Ok(()) }) diff --git a/proxmox-rrd/src/cache.rs b/proxmox-rrd/src/cache.rs index e3d2f8d5..683c8c4e 100644 --- a/proxmox-rrd/src/cache.rs +++ b/proxmox-rrd/src/cache.rs @@ -67,8 +67,8 @@ impl Cache { create_path( &basedir, - Some(dir_options.clone()), - Some(dir_options.clone()), + Some(&dir_options), + Some(&dir_options), ) .map_err(|err: Error| format_err!("unable to create rrdb stat dir - {}", err))?; diff --git a/proxmox-rrd/src/cache/journal.rs b/proxmox-rrd/src/cache/journal.rs index c196b342..447c0690 100644 --- a/proxmox-rrd/src/cache/journal.rs +++ b/proxmox-rrd/src/cache/journal.rs @@ -116,7 +116,7 @@ impl JournalState { &journal_path, flags, &[], - self.config.file_options.clone(), + &self.config.file_options, false, )?; Ok(BufReader::new(journal)) @@ -131,7 +131,7 @@ impl JournalState { &journal_path, flags, &[], - config.file_options.clone(), + &config.file_options, false, )?; Ok(journal) diff --git a/proxmox-rrd/src/cache/rrd_map.rs b/proxmox-rrd/src/cache/rrd_map.rs index 881b3987..8c09e2af 100644 --- a/proxmox-rrd/src/cache/rrd_map.rs +++ b/proxmox-rrd/src/cache/rrd_map.rs @@ -46,8 +46,8 @@ impl RRDMap { path.push(rel_path); create_path( path.parent().unwrap(), - Some(self.config.dir_options.clone()), - Some(self.config.dir_options.clone()), + Some(&self.config.dir_options), + Some(&self.config.dir_options), )?; let mut rrd = (self.load_rrd_cb)(&path, rel_path, dst); diff --git a/proxmox-rrd/src/rrd.rs b/proxmox-rrd/src/rrd.rs index 440abe06..2e8f0f06 100644 --- a/proxmox-rrd/src/rrd.rs +++ b/proxmox-rrd/src/rrd.rs @@ -424,7 +424,7 @@ impl Database { options: CreateOptions, avoid_page_cache: bool, ) -> Result<(), Error> { - let (fd, tmp_path) = make_tmp_file(path, options)?; + let (fd, tmp_path) = make_tmp_file(path, &options)?; let mut file = unsafe { std::fs::File::from_raw_fd(fd.into_raw_fd()) }; let mut try_block = || -> Result<(), Error> { diff --git a/proxmox-subscription/src/files.rs b/proxmox-subscription/src/files.rs index 37008f4a..f0ff9bf4 100644 --- a/proxmox-subscription/src/files.rs +++ b/proxmox-subscription/src/files.rs @@ -127,7 +127,7 @@ pub fn write_subscription>( format!("{}\n{}\n{}\n", info.key.as_ref().unwrap(), csum, encoded) }; - replace_file(path, raw.as_bytes(), file_opts, true)?; + replace_file(path, raw.as_bytes(), &file_opts, true)?; Ok(()) } @@ -152,7 +152,7 @@ pub fn update_apt_auth>( let conf = format!("machine {url}\n login {}\n password {}\n", key, password,); // we use a namespaced .conf file, so just overwrite.. - replace_file(path, conf.as_bytes(), file_opts, true) + replace_file(path, conf.as_bytes(), &file_opts, true) .map_err(|e| format_err!("Error saving apt auth config - {}", e))?; } _ => match std::fs::remove_file(path) { diff --git a/proxmox-sys/src/fs/dir.rs b/proxmox-sys/src/fs/dir.rs index c39b9fdf..8e75111a 100644 --- a/proxmox-sys/src/fs/dir.rs +++ b/proxmox-sys/src/fs/dir.rs @@ -14,7 +14,7 @@ use crate::fs::{fchown, CreateOptions}; /// Creates directory at the provided path with specified ownership. /// /// Errors if the directory already exists. -pub fn create_dir>(path: P, options: CreateOptions) -> Result<(), nix::Error> { +pub fn create_dir>(path: P, options: &CreateOptions) -> Result<(), nix::Error> { // clippy bug?: from_bits_truncate is actually a const fn... #[allow(clippy::or_fun_call)] let mode: stat::Mode = options @@ -87,7 +87,7 @@ pub fn ensure_dir_exists>( /// create_path( /// "/var/lib/mytool/wwwdata", /// None, -/// Some(CreateOptions::new() +/// Some(&CreateOptions::new() /// .perm(Mode::from_bits(0o777).unwrap()) /// .owner(Uid::from_raw(33)) /// ), @@ -97,16 +97,16 @@ pub fn ensure_dir_exists>( /// ``` pub fn create_path>( path: P, - intermediate_opts: Option, - final_opts: Option, + intermediate_opts: Option<&CreateOptions>, + final_opts: Option<&CreateOptions>, ) -> Result { create_path_do(path.as_ref(), intermediate_opts, final_opts) } fn create_path_do( path: &Path, - intermediate_opts: Option, - final_opts: Option, + intermediate_opts: Option<&CreateOptions>, + final_opts: Option<&CreateOptions>, ) -> Result { use std::path::Component; @@ -146,8 +146,8 @@ fn create_path_do( fn create_path_at_do( mut at: OwnedFd, mut iter: std::iter::Peekable, - intermediate_opts: Option, - final_opts: Option, + intermediate_opts: Option<&CreateOptions>, + final_opts: Option<&CreateOptions>, ) -> Result { let mut created = false; loop { @@ -206,9 +206,9 @@ mod tests { fn test_create_path() { create_path( "testdir/testsub/testsub2/testfinal", - Some(CreateOptions::new().perm(stat::Mode::from_bits_truncate(0o755))), + Some(&CreateOptions::new().perm(stat::Mode::from_bits_truncate(0o755))), Some( - CreateOptions::new() + &CreateOptions::new() .owner(nix::unistd::Uid::effective()) .group(nix::unistd::Gid::effective()), ), diff --git a/proxmox-sys/src/fs/file.rs b/proxmox-sys/src/fs/file.rs index ac513891..41915ebb 100644 --- a/proxmox-sys/src/fs/file.rs +++ b/proxmox-sys/src/fs/file.rs @@ -128,7 +128,7 @@ pub fn file_read_firstline>(path: P) -> Result { /// a RawFd and PathBuf for it pub fn make_tmp_file>( path: P, - options: CreateOptions, + options: &CreateOptions, ) -> Result<(File, PathBuf), Error> { let path = path.as_ref(); @@ -159,7 +159,7 @@ pub fn make_tmp_file>( pub fn replace_file>( path: P, data: &[u8], - options: CreateOptions, + options: &CreateOptions, fsync: bool, ) -> Result<(), Error> { let (fd, tmp_path) = make_tmp_file(&path, options)?; @@ -204,7 +204,7 @@ pub fn atomic_open_or_create_file>( path: P, mut oflag: OFlag, initial_data: &[u8], - options: CreateOptions, + options: &CreateOptions, fsync: bool, ) -> Result { let path = path.as_ref(); @@ -410,7 +410,7 @@ pub fn open_file_locked>( path: P, timeout: Duration, exclusive: bool, - options: CreateOptions, + options: &CreateOptions, ) -> Result { let path = path.as_ref(); diff --git a/proxmox-sys/src/logrotate.rs b/proxmox-sys/src/logrotate.rs index 704a18ce..af09723f 100644 --- a/proxmox-sys/src/logrotate.rs +++ b/proxmox-sys/src/logrotate.rs @@ -64,7 +64,7 @@ impl LogRotate { options: &CreateOptions, ) -> Result<(), Error> { let mut source = File::open(source_path)?; - let (fd, tmp_path) = make_tmp_file(target_path, options.clone())?; + let (fd, tmp_path) = make_tmp_file(target_path, options)?; let target = unsafe { File::from_raw_fd(fd.into_raw_fd()) }; let mut encoder = match zstd::stream::write::Encoder::new(target, 0) { Ok(encoder) => encoder, -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel