File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,16 @@ impl TempDir {
101101 Err ( Self :: already_exists ( ) )
102102 }
103103
104+ /// Make this directory persistent.
105+ ///
106+ /// This corresponds to [`tempfile::TempDir::into_path`], but returns a [`Dir`].
107+ ///
108+ /// [`tempfile::TempDir::into_path`]: https://docs.rs/tempfile/latest/tempfile/struct.TempDir.html#method.into_path
109+ /// [`Dir`]: https://docs.rs/cap-std/latest/cap_std/fs/struct.Dir.html
110+ pub fn into_dir ( mut self ) -> io:: Result < Dir > {
111+ Ok ( self . dir . take ( ) . unwrap ( ) )
112+ }
113+
104114 /// Closes and removes the temporary directory, returning a `Result`.
105115 ///
106116 /// This corresponds to [`tempfile::TempDir::close`].
@@ -222,6 +232,15 @@ fn close_tempdir() {
222232 t. close ( ) . unwrap ( ) ;
223233}
224234
235+ #[ test]
236+ fn persist_tempdir ( ) {
237+ use crate :: ambient_authority;
238+
239+ let t = tempdir ( ambient_authority ( ) ) . unwrap ( ) ;
240+ let d = t. into_dir ( ) . unwrap ( ) ;
241+ assert ! ( d. exists( "." ) ) ;
242+ }
243+
225244#[ test]
226245fn drop_tempdir_in ( ) {
227246 use crate :: ambient_authority;
You can’t perform that action at this time.
0 commit comments