From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox] make_tmp_file: return File instead of Fd
Date: Wed, 14 Jul 2021 12:27:36 +0200 [thread overview]
Message-ID: <20210714102736.1288034-1-dietmar@proxmox.com> (raw)
---
proxmox/src/tools/fs.rs | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/proxmox/src/tools/fs.rs b/proxmox/src/tools/fs.rs
index cd0ba35..12e96bd 100644
--- a/proxmox/src/tools/fs.rs
+++ b/proxmox/src/tools/fs.rs
@@ -126,14 +126,14 @@ pub fn file_read_firstline<P: AsRef<Path>>(path: P) -> Result<String, Error> {
pub fn make_tmp_file<P: AsRef<Path>>(
path: P,
options: CreateOptions,
-) -> Result<(Fd, PathBuf), Error> {
+) -> Result<(File, PathBuf), Error> {
let path = path.as_ref();
// use mkstemp here, because it works with different processes, threads, even tokio tasks
let mut template = path.to_owned();
template.set_extension("tmp_XXXXXX");
- let (fd, tmp_path) = match unistd::mkstemp(&template) {
- Ok((fd, path)) => (unsafe { Fd::from_raw_fd(fd) }, path),
+ let (file, tmp_path) = match unistd::mkstemp(&template) {
+ Ok((fd, path)) => (unsafe { File::from_raw_fd(fd) }, path),
Err(err) => bail!("mkstemp {:?} failed: {}", template, err),
};
@@ -143,19 +143,19 @@ pub fn make_tmp_file<P: AsRef<Path>>(
.perm
.unwrap_or(stat::Mode::from_bits_truncate(0o644));
- if let Err(err) = stat::fchmod(fd.as_raw_fd(), mode) {
+ if let Err(err) = stat::fchmod(file.as_raw_fd(), mode) {
let _ = unistd::unlink(&tmp_path);
bail!("fchmod {:?} failed: {}", tmp_path, err);
}
if options.owner.is_some() || options.group.is_some() {
- if let Err(err) = fchown(fd.as_raw_fd(), options.owner, options.group) {
+ if let Err(err) = fchown(file.as_raw_fd(), options.owner, options.group) {
let _ = unistd::unlink(&tmp_path);
bail!("fchown {:?} failed: {}", tmp_path, err);
}
}
- Ok((fd, tmp_path))
+ Ok((file, tmp_path))
}
/// Atomically replace a file.
--
2.30.2
next reply other threads:[~2021-07-14 10:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-14 10:27 Dietmar Maurer [this message]
2021-07-14 11:49 ` Thomas Lamprecht
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=20210714102736.1288034-1-dietmar@proxmox.com \
--to=dietmar@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.