-use std;
use std::env;
use std::error;
use std::ffi::OsStr;
/// ```
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
}
/// 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
///
// 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(())
}
}
}
- /// 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`].
// 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(())
}
// 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)
}
///
/// 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)
}
/// 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.
///
}
}
- /// 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.
///
/// # 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.
///