]> git.proxmox.com Git - rustc.git/blobdiff - src/vendor/tempfile/src/file/imp/unix.rs
New upstream version 1.28.0~beta.14+dfsg1
[rustc.git] / src / vendor / tempfile / src / file / imp / unix.rs
index 9eb31147bbf6651014d064243d94c593fe12dfe3..f8766d0dcdfdf909392c57d3efd59e93704ff796 100644 (file)
@@ -1,7 +1,7 @@
 #[cfg(not(target_os = "redox"))]
 use libc::{c_char, c_int, link, rename, unlink, O_CLOEXEC, O_CREAT, O_EXCL, O_RDWR};
 use std::ffi::CString;
-use std::fs::{File, OpenOptions};
+use std::fs::{self, File, OpenOptions};
 use std::io;
 use std::os::unix::ffi::OsStrExt;
 use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
@@ -63,6 +63,14 @@ pub fn create_named(path: PathBuf) -> io::Result<File> {
     }
 }
 
+fn create_unlinked(path: &Path) -> io::Result<File> {
+    let f = create_named(path)?;
+    // don't care whether the path has already been unlinked,
+    // but perhaps there are some IO error conditions we should send up?
+    let _ = fs::remove_file(path);
+    Ok(f)
+}
+
 #[cfg(target_os = "linux")]
 pub fn create(dir: &Path) -> io::Result<File> {
     use libc::O_TMPFILE;
@@ -86,7 +94,7 @@ pub fn create(dir: &Path) -> io::Result<File> {
 
 fn create_unix(dir: &Path) -> io::Result<File> {
     util::create_helper(dir, ".tmp", "", ::NUM_RAND_CHARS, |path| {
-        create_named(&path)
+        create_unlinked(&path)
     })
 }