From 26c06df420d0f26c826d89a23ff48ef4a55d93a1 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 14 Jul 2021 12:26:24 +0200 Subject: [PATCH] make_tmp_file: return File instead of Fd --- 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 cd0ba359..12e96bd6 100644 --- a/proxmox/src/tools/fs.rs +++ b/proxmox/src/tools/fs.rs @@ -126,14 +126,14 @@ pub fn file_read_firstline>(path: P) -> Result { pub fn make_tmp_file>( 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>( .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.