1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//! # async-tempfile
//!
//! Provides the [`TempFile`] struct, an asynchronous wrapper based on `tokio::fs` for temporary
//! files that will be automatically deleted when the last reference to the struct is dropped.
//!
//! ```
//! use async_tempfile::TempFile;
//!
//! #[tokio::main]
//! async fn main() {
//! let parent = TempFile::new().await.unwrap();
//!
//! // The cloned reference will not delete the file when dropped.
//! {
//! let nested = parent.open_rw().await.unwrap();
//! assert_eq!(nested.file_path(), parent.file_path());
//! assert!(nested.file_path().is_file());
//! }
//!
//! // The file still exists; it will be deleted when `parent` is dropped.
//! assert!(parent.file_path().is_file());
//! }
//! ```
//!
//! ## Features
//!
//! * `uuid` - Enables UUID-based random file name generation via the [`uuid`](https://crates.io/crates/uuid) crate
//! and the `new_with_uuid*` group of methods. Not enabled by default; `new`/`new_in` work without it.
// Document crate features on docs.rs.
// This crate deletes files purely from safe code; no `unsafe` is permitted.
pub use ;
pub use ;
pub use RandomName;
pub use TempDir;
pub use TempFile;
use Path;
use ;
/// Returns whether `path` is a directory, using async I/O so the calling task
/// does not block a runtime worker thread on the `stat` syscall.
pub async
/// Returns whether `path` is a regular file, using async I/O (see [`path_is_dir`]).
pub async
/// Returns `true` if `affix` is safe to splice into a file name.
///
/// `prefix`/`suffix` are composed into a single path component
/// (`{prefix}{random}{suffix}`). A path separator in either would let the
/// composed name escape the target directory once joined onto it: `Path::join`
/// replaces the base entirely when the fragment is absolute, and a fragment
/// containing `..` resolves to a parent directory when the OS interprets the
/// resulting path. We therefore reject any affix containing a separator
/// ([`std::path::is_separator`], which is platform-aware: `/` everywhere, plus
/// `\` on Windows) rather than letting it reach the filesystem.
pub
/// Determines the ownership of a temporary file or directory.
/// Lock-free, interior-mutable storage of an [`Ownership`] value, shared across
/// all clones via the `Arc`-wrapped core.
///
/// Lock-free is a hard requirement, not an optimization: the value is read from
/// `Drop`, which may run on a runtime worker thread and therefore must never
/// block on a lock. `keep`, `persist`, `drop_async`, and `close` flip it to
/// `Borrowed` to disable automatic deletion.
pub ;