about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrina-Gabriela Popa <irinagpopa@gmail.com>2017-11-27 17:21:13 +0200
committerIrina-Gabriela Popa <irinagpopa@gmail.com>2017-12-04 18:25:31 +0200
commit2c175df013a701321e44bcdba3c7ba7772ed3b94 (patch)
treed56166ea947d1850dacfb349c9e4f0ac03be83ed
parentdda924ab6a15ebccfa1be0bff5b88390f4195afd (diff)
downloadrust-2c175df013a701321e44bcdba3c7ba7772ed3b94.tar.gz
rust-2c175df013a701321e44bcdba3c7ba7772ed3b94.zip
rustc_back: replace tempdir with crates.io version.
-rw-r--r--src/Cargo.lock2
-rw-r--r--src/librustc_back/lib.rs1
-rw-r--r--src/librustc_back/tempdir.rs114
-rw-r--r--src/librustc_trans/Cargo.toml1
-rw-r--r--src/librustc_trans/back/link.rs2
-rw-r--r--src/librustc_trans/lib.rs1
-rw-r--r--src/librustdoc/Cargo.toml1
-rw-r--r--src/librustdoc/lib.rs1
-rw-r--r--src/librustdoc/test.rs2
-rw-r--r--src/test/run-pass-fulldeps/create-dir-all-bare.rs4
-rw-r--r--src/test/run-pass-fulldeps/issue-15149.rs4
-rw-r--r--src/test/run-pass-fulldeps/rename-directory.rs4
-rw-r--r--src/test/run-pass-fulldeps/stdio-from.rs4
-rw-r--r--src/test/run-pass-fulldeps/switch-stdout.rs4
14 files changed, 18 insertions, 127 deletions
diff --git a/src/Cargo.lock b/src/Cargo.lock
index 0ee46910f7d..dc15486fe7c 100644
--- a/src/Cargo.lock
+++ b/src/Cargo.lock
@@ -1960,6 +1960,7 @@ dependencies = [
  "serialize 0.0.0",
  "syntax 0.0.0",
  "syntax_pos 0.0.0",
+ "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -2013,6 +2014,7 @@ dependencies = [
  "html-diff 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs
index e338ee7bd93..ccf1db778d2 100644
--- a/src/librustc_back/lib.rs
+++ b/src/librustc_back/lib.rs
@@ -36,7 +36,6 @@ extern crate serialize;
 
 extern crate serialize as rustc_serialize; // used by deriving
 
-pub mod tempdir;
 pub mod target;
 
 use std::str::FromStr;
diff --git a/src/librustc_back/tempdir.rs b/src/librustc_back/tempdir.rs
deleted file mode 100644
index 1a251536622..00000000000
--- a/src/librustc_back/tempdir.rs
+++ /dev/null
@@ -1,114 +0,0 @@
-// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::env;
-use std::io::{self, Error, ErrorKind};
-use std::fs;
-use std::path::{self, PathBuf, Path};
-use rand::{thread_rng, Rng};
-
-/// A wrapper for a path to temporary directory implementing automatic
-/// scope-based deletion.
-pub struct TempDir {
-    path: Option<PathBuf>,
-}
-
-// How many times should we (re)try finding an unused random name? It should be
-// enough that an attacker will run out of luck before we run out of patience.
-const NUM_RETRIES: u32 = 1 << 31;
-// How many characters should we include in a random file name? It needs to
-// be enough to dissuade an attacker from trying to preemptively create names
-// of that length, but not so huge that we unnecessarily drain the random number
-// generator of entropy.
-const NUM_RAND_CHARS: usize = 12;
-
-impl TempDir {
-    /// Attempts to make a temporary directory inside of `tmpdir` whose name
-    /// will have the prefix `prefix`. The directory will be automatically
-    /// deleted once the returned wrapper is destroyed.
-    ///
-    /// If no directory can be created, `Err` is returned.
-    #[allow(deprecated)] // rand usage
-    pub fn new_in<P: AsRef<Path>>(tmpdir: P, prefix: &str)
-                                  -> io::Result<TempDir> {
-        Self::_new_in(tmpdir.as_ref(), prefix)
-    }
-
-    fn _new_in(tmpdir: &Path, prefix: &str) -> io::Result<TempDir> {
-        let storage;
-        let mut tmpdir = tmpdir;
-        if !tmpdir.is_absolute() {
-            let cur_dir = env::current_dir()?;
-            storage = cur_dir.join(tmpdir);
-            tmpdir = &storage;
-            // return TempDir::new_in(&cur_dir.join(tmpdir), prefix);
-        }
-
-        let mut rng = thread_rng();
-        for _ in 0..NUM_RETRIES {
-            let suffix: String = rng.gen_ascii_chars().take(NUM_RAND_CHARS).collect();
-            let leaf = if !prefix.is_empty() {
-                format!("{}.{}", prefix, suffix)
-            } else {
-                // If we're given an empty string for a prefix, then creating a
-                // directory starting with "." would lead to it being
-                // semi-invisible on some systems.
-                suffix
-            };
-            let path = tmpdir.join(&leaf);
-            match fs::create_dir(&path) {
-                Ok(_) => return Ok(TempDir { path: Some(path) }),
-                Err(ref e) if e.kind() == ErrorKind::AlreadyExists => {}
-                Err(e) => return Err(e)
-            }
-        }
-
-        Err(Error::new(ErrorKind::AlreadyExists,
-                       "too many temporary directories already exist"))
-    }
-
-    /// Attempts to make a temporary directory inside of `env::temp_dir()` whose
-    /// name will have the prefix `prefix`. The directory will be automatically
-    /// deleted once the returned wrapper is destroyed.
-    ///
-    /// If no directory can be created, `Err` is returned.
-    pub fn new(prefix: &str) -> io::Result<TempDir> {
-        TempDir::new_in(&env::temp_dir(), prefix)
-    }
-
-    /// Unwrap the wrapped `std::path::Path` from the `TempDir` wrapper.
-    /// This discards the wrapper so that the automatic deletion of the
-    /// temporary directory is prevented.
-    pub fn into_path(mut self) -> PathBuf {
-        self.path.take().unwrap()
-    }
-
-    /// Access the wrapped `std::path::Path` to the temporary directory.
-    pub fn path(&self) -> &path::Path {
-        self.path.as_ref().unwrap()
-    }
-
-    fn cleanup_dir(&mut self) -> io::Result<()> {
-        match self.path {
-            Some(ref p) => fs::remove_dir_all(p),
-            None => Ok(())
-        }
-    }
-}
-
-impl Drop for TempDir {
-    fn drop(&mut self) {
-        let _ = self.cleanup_dir();
-    }
-}
-
-// the tests for this module need to change the path using change_dir,
-// and this doesn't play nicely with other tests so these unit tests are located
-// in src/test/run-pass/tempfile.rs
diff --git a/src/librustc_trans/Cargo.toml b/src/librustc_trans/Cargo.toml
index 96102cad3ef..d8318ea8082 100644
--- a/src/librustc_trans/Cargo.toml
+++ b/src/librustc_trans/Cargo.toml
@@ -32,6 +32,7 @@ rustc_trans_utils = { path = "../librustc_trans_utils" }
 serialize = { path = "../libserialize" }
 syntax = { path = "../libsyntax" }
 syntax_pos = { path = "../libsyntax_pos" }
+tempdir = "0.3"
 
 [target."cfg(windows)".dependencies]
 cc = "1.0.1"
diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs
index e0eef1f5764..a182d7c6fbe 100644
--- a/src/librustc_trans/back/link.rs
+++ b/src/librustc_trans/back/link.rs
@@ -26,7 +26,7 @@ use {CrateTranslation, CrateInfo};
 use rustc::util::common::time;
 use rustc::util::fs::fix_windows_verbatim_for_gcc;
 use rustc::hir::def_id::CrateNum;
-use rustc_back::tempdir::TempDir;
+use tempdir::TempDir;
 use rustc_back::{PanicStrategy, RelroLevel, LinkerFlavor};
 use context::get_reloc_model;
 use llvm;
diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs
index 3d1bd81fe21..3c2e56bf2a1 100644
--- a/src/librustc_trans/lib.rs
+++ b/src/librustc_trans/lib.rs
@@ -63,6 +63,7 @@ extern crate rustc_errors as errors;
 extern crate serialize;
 #[cfg(windows)]
 extern crate cc; // Used to locate MSVC
+extern crate tempdir;
 
 pub use base::trans_crate;
 use back::bytecode::RLIB_BYTECODE_EXTENSION;
diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml
index eca3ebe9130..fd8a6e0b593 100644
--- a/src/librustdoc/Cargo.toml
+++ b/src/librustdoc/Cargo.toml
@@ -14,6 +14,7 @@ doctest = false
 log = "0.3"
 pulldown-cmark = { version = "0.1.0", default-features = false }
 html-diff = "0.0.5"
+tempdir = "0.3"
 
 [build-dependencies]
 build_helper = { path = "../build_helper" }
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index 967076779ad..f0bb87015f8 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -48,6 +48,7 @@ extern crate std_unicode;
 #[macro_use] extern crate log;
 extern crate rustc_errors as errors;
 extern crate pulldown_cmark;
+extern crate tempdir;
 
 extern crate serialize as rustc_serialize; // used by deriving
 
diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs
index 98369949c02..74a16cb867d 100644
--- a/src/librustdoc/test.rs
+++ b/src/librustdoc/test.rs
@@ -28,7 +28,7 @@ use rustc::session::{self, CompileIncomplete, config};
 use rustc::session::config::{OutputType, OutputTypes, Externs};
 use rustc::session::search_paths::{SearchPaths, PathKind};
 use rustc_metadata::dynamic_lib::DynamicLibrary;
-use rustc_back::tempdir::TempDir;
+use tempdir::TempDir;
 use rustc_driver::{self, driver, Compilation};
 use rustc_driver::driver::phase_2_configure_and_expand;
 use rustc_metadata::cstore::CStore;
diff --git a/src/test/run-pass-fulldeps/create-dir-all-bare.rs b/src/test/run-pass-fulldeps/create-dir-all-bare.rs
index e22736d7785..ba42cb870c9 100644
--- a/src/test/run-pass-fulldeps/create-dir-all-bare.rs
+++ b/src/test/run-pass-fulldeps/create-dir-all-bare.rs
@@ -12,11 +12,11 @@
 
 #![feature(rustc_private)]
 
-extern crate rustc_back;
+extern crate tempdir;
 
 use std::env;
 use std::fs;
-use rustc_back::tempdir::TempDir;
+use tempdir::TempDir;
 
 fn main() {
     let td = TempDir::new("create-dir-all-bare").unwrap();
diff --git a/src/test/run-pass-fulldeps/issue-15149.rs b/src/test/run-pass-fulldeps/issue-15149.rs
index c0ed7165afe..121fd4a9825 100644
--- a/src/test/run-pass-fulldeps/issue-15149.rs
+++ b/src/test/run-pass-fulldeps/issue-15149.rs
@@ -13,13 +13,13 @@
 
 #![feature(rustc_private)]
 
-extern crate rustc_back;
+extern crate tempdir;
 
 use std::env;
 use std::fs;
 use std::process;
 use std::str;
-use rustc_back::tempdir::TempDir;
+use tempdir::TempDir;
 
 fn main() {
     // If we're the child, make sure we were invoked correctly
diff --git a/src/test/run-pass-fulldeps/rename-directory.rs b/src/test/run-pass-fulldeps/rename-directory.rs
index f107e104281..7a2a4343522 100644
--- a/src/test/run-pass-fulldeps/rename-directory.rs
+++ b/src/test/run-pass-fulldeps/rename-directory.rs
@@ -15,11 +15,11 @@
 
 #![feature(rustc_private)]
 
-extern crate rustc_back;
+extern crate tempdir;
 
 use std::ffi::CString;
 use std::fs::{self, File};
-use rustc_back::tempdir::TempDir;
+use tempdir::TempDir;
 
 fn rename_directory() {
     let tmpdir = TempDir::new("rename_directory").ok().expect("rename_directory failed");
diff --git a/src/test/run-pass-fulldeps/stdio-from.rs b/src/test/run-pass-fulldeps/stdio-from.rs
index f64bbf9312c..535ab711f5b 100644
--- a/src/test/run-pass-fulldeps/stdio-from.rs
+++ b/src/test/run-pass-fulldeps/stdio-from.rs
@@ -12,7 +12,7 @@
 
 #![feature(rustc_private)]
 
-extern crate rustc_back;
+extern crate tempdir;
 
 use std::env;
 use std::fs::File;
@@ -20,7 +20,7 @@ use std::io;
 use std::io::{Read, Write};
 use std::process::{Command, Stdio};
 
-use rustc_back::tempdir::TempDir;
+use tempdir::TempDir;
 
 fn main() {
     if env::args().len() > 1 {
diff --git a/src/test/run-pass-fulldeps/switch-stdout.rs b/src/test/run-pass-fulldeps/switch-stdout.rs
index 4542e27545a..16f7e283285 100644
--- a/src/test/run-pass-fulldeps/switch-stdout.rs
+++ b/src/test/run-pass-fulldeps/switch-stdout.rs
@@ -10,12 +10,12 @@
 
 #![feature(rustc_private)]
 
-extern crate rustc_back;
+extern crate tempdir;
 
 use std::fs::File;
 use std::io::{Read, Write};
 
-use rustc_back::tempdir::TempDir;
+use tempdir::TempDir;
 
 #[cfg(unix)]
 fn switch_stdout_to(file: File) {