]> git.proxmox.com Git - cargo.git/blobdiff - vendor/tempfile/src/file/mod.rs
New upstream version 0.52.0
[cargo.git] / vendor / tempfile / src / file / mod.rs
index ce70cac731464c36fd6d073f8c07d51b7b13803f..31fdd4bed0431da5fc6dc1c6505b183ee3970766 100644 (file)
@@ -1,4 +1,3 @@
-use std;
 use std::env;
 use std::error;
 use std::ffi::OsStr;
@@ -178,7 +177,7 @@ impl TempPath {
     /// ```
     pub fn close(mut self) -> io::Result<()> {
         let result = fs::remove_file(&self.path).with_err_path(|| &self.path);
-        mem::replace(&mut self.path, PathBuf::new());
+        self.path = PathBuf::new();
         mem::forget(self);
         result
     }
@@ -189,7 +188,10 @@ impl TempPath {
     /// If this method fails, it will return `self` in the resulting
     /// [`PathPersistError`].
     ///
-    /// Note: Temporary files cannot be persisted across filesystems.
+    /// Note: Temporary files cannot be persisted across filesystems. Also
+    /// neither the file contents nor the containing directory are
+    /// synchronized, so the update may not yet have reached the disk when
+    /// `persist` returns.
     ///
     /// # Security
     ///
@@ -229,7 +231,7 @@ impl TempPath {
                 // Don't drop `self`. We don't want to try deleting the old
                 // temporary file path. (It'll fail, but the failure is never
                 // seen.)
-                mem::replace(&mut self.path, PathBuf::new());
+                self.path = PathBuf::new();
                 mem::forget(self);
                 Ok(())
             }
@@ -240,7 +242,7 @@ impl TempPath {
         }
     }
 
-    /// Persist the temporary file at the target path iff no file exists there.
+    /// Persist the temporary file at the target path if and only if no file exists there.
     ///
     /// If a file exists at the target path, fail. If this method fails, it will
     /// return `self` in the resulting [`PathPersistError`].
@@ -291,7 +293,7 @@ impl TempPath {
                 // Don't drop `self`. We don't want to try deleting the old
                 // temporary file path. (It'll fail, but the failure is never
                 // seen.)
-                mem::replace(&mut self.path, PathBuf::new());
+                self.path = PathBuf::new();
                 mem::forget(self);
                 Ok(())
             }
@@ -339,8 +341,7 @@ impl TempPath {
                 // Don't drop `self`. We don't want to try deleting the old
                 // temporary file path. (It'll fail, but the failure is never
                 // seen.)
-                let mut path = PathBuf::new();
-                mem::swap(&mut self.path, &mut path);
+                let path = mem::replace(&mut self.path, PathBuf::new());
                 mem::forget(self);
                 Ok(path)
             }
@@ -584,7 +585,7 @@ impl NamedTempFile {
     ///
     /// See [`NamedTempFile::new()`] for details.
     ///
-    /// [`NamedTempFile::new()`]: #method.new_in
+    /// [`NamedTempFile::new()`]: #method.new
     pub fn new_in<P: AsRef<Path>>(dir: P) -> io::Result<NamedTempFile> {
         Builder::new().tempfile_in(dir)
     }
@@ -662,11 +663,14 @@ impl NamedTempFile {
     /// If this method fails, it will return `self` in the resulting
     /// [`PersistError`].
     ///
-    /// Note: Temporary files cannot be persisted across filesystems.
+    /// Note: Temporary files cannot be persisted across filesystems. Also
+    /// neither the file contents nor the containing directory are
+    /// synchronized, so the update may not yet have reached the disk when
+    /// `persist` returns.
     ///
     /// # Security
     ///
-    /// This method persists the temporary file using it's path and may not be
+    /// This method persists the temporary file using its path and may not be
     /// secure in the in all cases. Please read the security section on the top
     /// level documentation of this type for details.
     ///
@@ -709,7 +713,7 @@ impl NamedTempFile {
         }
     }
 
-    /// Persist the temporary file at the target path iff no file exists there.
+    /// Persist the temporary file at the target path if and only if no file exists there.
     ///
     /// If a file exists at the target path, fail. If this method fails, it will
     /// return `self` in the resulting PersistError.
@@ -720,7 +724,7 @@ impl NamedTempFile {
     ///
     /// # Security
     ///
-    /// This method persists the temporary file using it's path and may not be
+    /// This method persists the temporary file using its path and may not be
     /// secure in the in all cases. Please read the security section on the top
     /// level documentation of this type for details.
     ///