fomat-macros icon indicating copy to clipboard operation
fomat-macros copied to clipboard

replace tempdir with tempfile, as tempdir is deprecated

Open alexanderkjall opened this issue 2 years ago • 1 comments

deprecation note here: https://crates.io/crates/tempdir

alexanderkjall avatar May 15 '22 09:05 alexanderkjall

This PR changes semantics of that part of code. To use the equivalent of deprecated tempdir::TempDir::new() you need to use builder to pass the prefix.

michalfita avatar Sep 16 '22 12:09 michalfita

Like that:

diff --git a/Cargo.toml b/Cargo.toml
index 78655eb..42dee13 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,4 +13,4 @@ license = "MIT"
 
 [dev-dependencies]
 tar = "0.4.9"
-tempdir = "0.3.5"
+tempfile = "3.3.0"
diff --git a/tests/capturing.rs b/tests/capturing.rs
index 551cc91..2f93e0f 100644
--- a/tests/capturing.rs
+++ b/tests/capturing.rs
@@ -1,7 +1,8 @@
-extern crate tempdir;
+extern crate tempfile;
 extern crate tar;
 
 use std::path::Path;
+use tempfile::Builder;
 
 const FILES: &'static [(&'static str, &'static str)] = &[
     ("Cargo.toml", r#"
@@ -83,8 +84,8 @@ fn capturing() {
         rootdir
     };
 
-    let pintdir = tempdir::TempDir::new("fomat-macros-capturing-test")
-        .expect("Can't create tempdir");
+    let pintdir = Builder::new()
+    .expect("Can't create tempdir");
     unpack_files(pintdir.as_ref(), rootdir.to_str().unwrap());
 
     assert!(

? E: This errors because unpack_files expects a path type:

expected struct `Path`, found struct `tempfile::Builder`

werdahias avatar Nov 16 '22 12:11 werdahias

From memory more like:

let pintdir = Builder::new()
    .prefix("my-temporary-note")
    .tempdir()
    .expect("Can't create tempdir"); 

michalfita avatar Nov 17 '22 15:11 michalfita

This builds fine for me:

diff --git a/Cargo.toml b/Cargo.toml
index 78655eb..42dee13 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,4 +13,4 @@ license = "MIT"
 
 [dev-dependencies]
 tar = "0.4.9"
-tempdir = "0.3.5"
+tempfile = "3.3.0"
diff --git a/tests/capturing.rs b/tests/capturing.rs
index 551cc91..925313b 100644
--- a/tests/capturing.rs
+++ b/tests/capturing.rs
@@ -1,7 +1,8 @@
-extern crate tempdir;
+extern crate tempfile;
 extern crate tar;
 
 use std::path::Path;
+use tempfile::Builder;
 
 const FILES: &'static [(&'static str, &'static str)] = &[
     ("Cargo.toml", r#"
@@ -83,9 +84,11 @@ fn capturing() {
         rootdir
     };
 
-    let pintdir = tempdir::TempDir::new("fomat-macros-capturing-test")
-        .expect("Can't create tempdir");
-    unpack_files(pintdir.as_ref(), rootdir.to_str().unwrap());
+    let pintdir = Builder::new()
+    .prefix("my-temporary-note")
+    .tempdir()
+    .expect("Can't create tempdir"); 
+    unpack_files( &pintdir.path(), rootdir.to_str().unwrap());
 
     assert!(
         Command::new("cargo").arg("build")

Please merge.

werdahias avatar Nov 17 '22 15:11 werdahias

@michalfita updated to preserve the prefix

alexanderkjall avatar Dec 06 '22 18:12 alexanderkjall

Looks good to me now.

michalfita avatar Dec 08 '22 14:12 michalfita