From: Shannon Sterz <s.sterz@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 03/19] tree-wide: remove clone calls on types that are `Copy`
Date: Thu, 6 Mar 2025 13:43:33 +0100 [thread overview]
Message-ID: <20250306124349.288370-4-s.sterz@proxmox.com> (raw)
In-Reply-To: <20250306124349.288370-1-s.sterz@proxmox.com>
this resolves a clippy lint that checks that `clone()` isn't called on
`Copy` types as that is unnecessary [1].
[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
---
proxmox-log/src/file_logger.rs | 3 +--
proxmox-rest-server/src/worker_task.rs | 9 ++-------
proxmox-rrd/src/cache.rs | 8 ++------
proxmox-rrd/src/cache/journal.rs | 18 ++++--------------
proxmox-rrd/src/cache/rrd_map.rs | 6 +++---
proxmox-shared-cache/src/lib.rs | 18 ++++--------------
proxmox-sys/src/logrotate.rs | 2 +-
7 files changed, 17 insertions(+), 47 deletions(-)
diff --git a/proxmox-log/src/file_logger.rs b/proxmox-log/src/file_logger.rs
index 1e67b450..39d16857 100644
--- a/proxmox-log/src/file_logger.rs
+++ b/proxmox-log/src/file_logger.rs
@@ -93,8 +93,7 @@ impl FileLogger {
flags |= OFlag::O_EXCL;
}
- let file =
- atomic_open_or_create_file(&file_name, flags, &[], options.file_opts.clone(), false)?;
+ let file = atomic_open_or_create_file(&file_name, flags, &[], options.file_opts, false)?;
Ok(file)
}
diff --git a/proxmox-rest-server/src/worker_task.rs b/proxmox-rest-server/src/worker_task.rs
index 24e2676e..9351bbee 100644
--- a/proxmox-rest-server/src/worker_task.rs
+++ b/proxmox-rest-server/src/worker_task.rs
@@ -136,7 +136,6 @@ impl WorkerTaskSetup {
fn lock_task_list_files(&self, exclusive: bool) -> Result<TaskListLockGuard, Error> {
let options = self
.file_opts
- .clone()
.perm(nix::sys::stat::Mode::from_bits_truncate(0o660));
let timeout = std::time::Duration::new(15, 0);
@@ -163,7 +162,6 @@ impl WorkerTaskSetup {
let mut path = self.log_directory(upid);
let dir_opts = self
.file_opts
- .clone()
.perm(nix::sys::stat::Mode::from_bits_truncate(0o755));
create_path(&path, None, Some(dir_opts))?;
@@ -222,7 +220,6 @@ impl WorkerTaskSetup {
let options = self
.file_opts
- .clone()
.perm(nix::sys::stat::Mode::from_bits_truncate(0o660));
replace_file(&self.active_tasks_fn, active_raw.as_bytes(), options, false)?;
@@ -237,7 +234,6 @@ impl WorkerTaskSetup {
if !finish_list.is_empty() {
let options = self
.file_opts
- .clone()
.perm(nix::sys::stat::Mode::from_bits_truncate(0o660));
let mut writer = atomic_open_or_create_file(
@@ -268,10 +264,9 @@ impl WorkerTaskSetup {
try_block!({
let dir_opts = self
.file_opts
- .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(())
})
@@ -901,7 +896,7 @@ impl WorkerTask {
exclusive: true,
prefix_time: true,
read: true,
- file_opts: setup.file_opts.clone(),
+ file_opts: setup.file_opts,
..Default::default()
};
let logger = FileLogger::new(path, logger_options)?;
diff --git a/proxmox-rrd/src/cache.rs b/proxmox-rrd/src/cache.rs
index 9dd85a16..29d46ed5 100644
--- a/proxmox-rrd/src/cache.rs
+++ b/proxmox-rrd/src/cache.rs
@@ -66,12 +66,8 @@ impl Cache {
let file_options = file_options.unwrap_or_default();
let dir_options = dir_options.unwrap_or_default();
- create_path(
- &basedir,
- Some(dir_options.clone()),
- Some(dir_options.clone()),
- )
- .map_err(|err: Error| format_err!("unable to create rrdb stat dir - {}", err))?;
+ create_path(&basedir, Some(dir_options), Some(dir_options))
+ .map_err(|err: Error| format_err!("unable to create rrdb stat dir - {}", err))?;
let config = Arc::new(CacheConfig {
basedir,
diff --git a/proxmox-rrd/src/cache/journal.rs b/proxmox-rrd/src/cache/journal.rs
index c196b342..fe48f23b 100644
--- a/proxmox-rrd/src/cache/journal.rs
+++ b/proxmox-rrd/src/cache/journal.rs
@@ -112,13 +112,8 @@ impl JournalState {
journal_path.push(RRD_JOURNAL_NAME);
let flags = OFlag::O_CLOEXEC | OFlag::O_RDONLY;
- let journal = atomic_open_or_create_file(
- &journal_path,
- flags,
- &[],
- self.config.file_options.clone(),
- false,
- )?;
+ let journal =
+ atomic_open_or_create_file(&journal_path, flags, &[], self.config.file_options, false)?;
Ok(BufReader::new(journal))
}
@@ -127,13 +122,8 @@ impl JournalState {
journal_path.push(RRD_JOURNAL_NAME);
let flags = OFlag::O_CLOEXEC | OFlag::O_WRONLY | OFlag::O_APPEND;
- let journal = atomic_open_or_create_file(
- &journal_path,
- flags,
- &[],
- config.file_options.clone(),
- false,
- )?;
+ let journal =
+ atomic_open_or_create_file(&journal_path, flags, &[], 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 0ef61cfa..27ea8e6e 100644
--- a/proxmox-rrd/src/cache/rrd_map.rs
+++ b/proxmox-rrd/src/cache/rrd_map.rs
@@ -51,8 +51,8 @@ impl RRDMap {
None => {
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),
)?;
(self.create_rrd_cb)(dst)
@@ -82,7 +82,7 @@ impl RRDMap {
if let Some(rrd) = self.map.get(rel_path) {
let mut path = self.config.basedir.clone();
path.push(rel_path);
- rrd.save(&path, self.config.file_options.clone(), true)
+ rrd.save(&path, self.config.file_options, true)
} else {
bail!("rrd file {} not loaded", rel_path);
}
diff --git a/proxmox-shared-cache/src/lib.rs b/proxmox-shared-cache/src/lib.rs
index d0b2148a..65abc1ac 100644
--- a/proxmox-shared-cache/src/lib.rs
+++ b/proxmox-shared-cache/src/lib.rs
@@ -127,7 +127,7 @@ impl SharedCache {
proxmox_sys::fs::replace_file(
&self.path,
new_content.as_bytes(),
- self.create_options.clone(),
+ self.create_options,
true,
)?;
@@ -137,7 +137,7 @@ impl SharedCache {
/// Removes all items from the cache.
pub fn delete(&self, lock_timeout: Duration) -> Result<(), Error> {
let _lock = self.lock(lock_timeout)?;
- proxmox_sys::fs::replace_file(&self.path, &[], self.create_options.clone(), true)?;
+ proxmox_sys::fs::replace_file(&self.path, &[], self.create_options, true)?;
Ok(())
}
@@ -145,12 +145,7 @@ impl SharedCache {
fn lock(&self, lock_timeout: Duration) -> Result<File, Error> {
let mut lockfile_path = self.path.clone();
lockfile_path.set_extension("lock");
- proxmox_sys::fs::open_file_locked(
- lockfile_path,
- lock_timeout,
- true,
- self.create_options.clone(),
- )
+ proxmox_sys::fs::open_file_locked(lockfile_path, lock_timeout, true, self.create_options)
}
}
@@ -178,12 +173,7 @@ mod tests {
.group(nix::unistd::Gid::effective())
.perm(nix::sys::stat::Mode::from_bits_truncate(0o700));
- proxmox_sys::fs::create_path(
- &path,
- Some(dir_options.clone()),
- Some(dir_options.clone()),
- )
- .unwrap();
+ proxmox_sys::fs::create_path(&path, Some(dir_options), Some(dir_options)).unwrap();
let cache = SharedCache::new(path.join("somekey"), options, keep_old).unwrap();
Self {
diff --git a/proxmox-sys/src/logrotate.rs b/proxmox-sys/src/logrotate.rs
index 704a18ce..cb96974a 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.5
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2025-03-06 12:44 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-06 12:43 [pbs-devel] [PATCH proxmox 00/19] clippy, test and doc clean up Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 01/19] io: clippy fix: replace `map()` followed by `any()` with just `any()` Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 02/19] tree-wide: add parantheses to clarify precedence Shannon Sterz
2025-03-06 12:43 ` Shannon Sterz [this message]
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 04/19] tfa: don't use block in conditions Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 05/19] tfa: remove needless `as_bytes` call Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 06/19] access-control/tfa: use `?` instead of unnecessary match statements Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 07/19] sys: add truncate option to `OpenOptions` in test case Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 08/19] router: allow `from_str` on Confirmation that is not for `FromStr` Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 09/19] auth-api/tfa: prefer `Display` over `ToString`/an inherent function Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 10/19] acme/auth-api: add `Default` for types with un-parameterized `new()` Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 11/19] shared-memory: specify generic types for transmute Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 12/19] router: ignore clippy lint `missing_transmute_annotations` Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 13/19] rest-server/router: ignore type complexity clippy lint Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 14/19] apt: ignore clippy lint about using a slice reference instead of `&Vec` Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 15/19] apt: ignore clippy lint about new having to return `Self` Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 16/19] network-api: ignore clippy lint about upper case acronyms Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 17/19] router: fix nested doc test cases to match inteded output Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 18/19] api-macro: re-order ObjectSchema fields to be sorted Shannon Sterz
2025-03-06 12:43 ` [pbs-devel] [PATCH proxmox 19/19] tree-wide: fix intra doc links Shannon Sterz
2025-03-06 14:26 ` [pbs-devel] applied-series: [PATCH proxmox 00/19] clippy, test and doc clean up Wolfgang Bumiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250306124349.288370-4-s.sterz@proxmox.com \
--to=s.sterz@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal