Replacing deprecated tempdir by tempfile crate

This commit is contained in:
João M. Bezerra 2021-08-13 03:12:23 -03:00
parent c9d4eea403
commit 7265effd65
3 changed files with 28 additions and 53 deletions

65
Cargo.lock generated
View File

@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3
[[package]] [[package]]
name = "adler" name = "adler"
version = "1.0.2" version = "1.0.2"
@ -90,12 +92,6 @@ dependencies = [
"miniz_oxide", "miniz_oxide",
] ]
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.3" version = "0.2.3"
@ -140,10 +136,10 @@ version = "0.1.5"
dependencies = [ dependencies = [
"bzip2", "bzip2",
"flate2", "flate2",
"rand 0.8.4", "rand",
"strsim", "strsim",
"tar", "tar",
"tempdir", "tempfile",
"walkdir", "walkdir",
"xz2", "xz2",
"zip", "zip",
@ -179,19 +175,6 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "rand"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
dependencies = [
"fuchsia-cprng",
"libc",
"rand_core 0.3.1",
"rdrand",
"winapi",
]
[[package]] [[package]]
name = "rand" name = "rand"
version = "0.8.4" version = "0.8.4"
@ -200,7 +183,8 @@ checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8"
dependencies = [ dependencies = [
"libc", "libc",
"rand_chacha", "rand_chacha",
"rand_core 0.6.3", "rand_core",
"rand_hc",
] ]
[[package]] [[package]]
@ -210,24 +194,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [ dependencies = [
"ppv-lite86", "ppv-lite86",
"rand_core 0.6.3", "rand_core",
] ]
[[package]]
name = "rand_core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
dependencies = [
"rand_core 0.4.2",
]
[[package]]
name = "rand_core"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
[[package]] [[package]]
name = "rand_core" name = "rand_core"
version = "0.6.3" version = "0.6.3"
@ -238,12 +207,12 @@ dependencies = [
] ]
[[package]] [[package]]
name = "rdrand" name = "rand_hc"
version = "0.4.0" version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7"
dependencies = [ dependencies = [
"rand_core 0.3.1", "rand_core",
] ]
[[package]] [[package]]
@ -302,13 +271,17 @@ dependencies = [
] ]
[[package]] [[package]]
name = "tempdir" name = "tempfile"
version = "0.3.7" version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22"
dependencies = [ dependencies = [
"rand 0.4.6", "cfg-if",
"libc",
"rand",
"redox_syscall",
"remove_dir_all", "remove_dir_all",
"winapi",
] ]
[[package]] [[package]]

View File

@ -22,7 +22,7 @@ xz2 = "0.1.6"
zip = "0.5.11" zip = "0.5.11"
[dev-dependencies] [dev-dependencies]
tempdir = "0.3.7" tempfile = "3.2.0"
rand = { version = "0.8.3", default-features = false, features = ["small_rng", "std"] } rand = { version = "0.8.3", default-features = false, features = ["small_rng", "std"] }
[profile.release] [profile.release]

View File

@ -6,7 +6,6 @@ use std::{
use ouch::{cli::Command, commands::run, oof}; use ouch::{cli::Command, commands::run, oof};
use rand::{rngs::SmallRng, RngCore, SeedableRng}; use rand::{rngs::SmallRng, RngCore, SeedableRng};
use tempdir::TempDir;
#[test] #[test]
/// Tests each format that supports multiple files with random input. /// Tests each format that supports multiple files with random input.
@ -39,10 +38,13 @@ fn test_compression_and_decompression(format: &str) -> bool {
// System temporary directory depends on the platform // System temporary directory depends on the platform
// For linux it is /tmp // For linux it is /tmp
let system_tmp = env::temp_dir(); let system_tmp = env::temp_dir();
// Create a folder that will be deleted on drop // Create a folder that will be deleted on drop
let testing_dir = String::from("ouch-testing-") + format; let testing_dir = tempfile::Builder::new()
let testing_dir = TempDir::new_in(system_tmp, &testing_dir).expect("Could not create tempdir"); .prefix("ouch-testing")
let testing_dir = testing_dir.path(); .tempdir_in(system_tmp)
.expect("Could not create testing_dir");
let testing_dir_path = testing_dir.path();
// Quantity of compressed files vary from 1 to 10 // Quantity of compressed files vary from 1 to 10
let quantity_of_files = rng.next_u32() % 10 + 1; let quantity_of_files = rng.next_u32() % 10 + 1;
@ -50,8 +52,8 @@ fn test_compression_and_decompression(format: &str) -> bool {
let contents_of_files: Vec<FileContent> = let contents_of_files: Vec<FileContent> =
(0..quantity_of_files).map(|_| generate_random_file_content(&mut rng)).collect(); (0..quantity_of_files).map(|_| generate_random_file_content(&mut rng)).collect();
let mut file_paths = create_files(&testing_dir, &contents_of_files); let mut file_paths = create_files(&testing_dir_path, &contents_of_files);
let compressed_archive_path = compress_files(&testing_dir, &file_paths, &format); let compressed_archive_path = compress_files(&testing_dir_path, &file_paths, &format);
let mut extracted_paths = extract_files(&compressed_archive_path); let mut extracted_paths = extract_files(&compressed_archive_path);
// // If you want to visualize the compressed and extracted files in the temporary directory // // If you want to visualize the compressed and extracted files in the temporary directory