]> git.lizzy.rs Git - rust.git/commitdiff
rustc_back: replace tempdir with crates.io version.
authorIrina-Gabriela Popa <irinagpopa@gmail.com>
Mon, 27 Nov 2017 15:21:13 +0000 (17:21 +0200)
committerIrina-Gabriela Popa <irinagpopa@gmail.com>
Mon, 4 Dec 2017 16:25:31 +0000 (18:25 +0200)
14 files changed:
src/Cargo.lock
src/librustc_back/lib.rs
src/librustc_back/tempdir.rs [deleted file]
src/librustc_trans/Cargo.toml
src/librustc_trans/back/link.rs
src/librustc_trans/lib.rs
src/librustdoc/Cargo.toml
src/librustdoc/lib.rs
src/librustdoc/test.rs
src/test/run-pass-fulldeps/create-dir-all-bare.rs
src/test/run-pass-fulldeps/issue-15149.rs
src/test/run-pass-fulldeps/rename-directory.rs
src/test/run-pass-fulldeps/stdio-from.rs
src/test/run-pass-fulldeps/switch-stdout.rs

index 0ee46910f7d6ef3991f11b16aa97c6a38c1a15fb..dc15486fe7cb25c4cc1ad5b67d914a763582b2bf 100644 (file)
@@ -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]]
index e338ee7bd932877b884d78d533e26f14028bd69a..ccf1db778d2967f6e9971c4225efed55245edb5e 100644 (file)
@@ -36,7 +36,6 @@
 
 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 (file)
index 1a25153..0000000
+++ /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
index 96102cad3ef5e1f57c5d50695d1c6ca347f58b1c..d8318ea808221f19853a4935379e2ac80a11fcb7 100644 (file)
@@ -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"
index e0eef1f5764b2d386da6c7a3ce92dd51878ff0a7..a182d7c6fbe06ec1c8cf004c1f68333f25287fa0 100644 (file)
@@ -26,7 +26,7 @@
 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;
index 3d1bd81fe21a31f1aa1fc37e4059e51ad4c87ec4..3c2e56bf2a12721b0402c551eea71d692357d12e 100644 (file)
@@ -63,6 +63,7 @@
 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;
index eca3ebe9130fd35eb39dcb679bed3e2493ab9009..fd8a6e0b5932644b486550888585d58d48566ca5 100644 (file)
@@ -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" }
index 967076779add05f041383cabbcaa9ccbc6fb6f06..f0bb87015f80579cd398bcf5569c2caf9e379df7 100644 (file)
@@ -48,6 +48,7 @@
 #[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
 
index 98369949c02a470aea0ebd40465f442fb3b6ecb3..74a16cb867d74015fad38da8f309f14a9119d3b1 100644 (file)
@@ -28,7 +28,7 @@
 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;
index e22736d77856a266fecb7e9b211214d3f4f3d1e5..ba42cb870c97edf124f38b8192c76314cfb0074f 100644 (file)
 
 #![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();
index c0ed7165afecac903a1c08258eccec8cf5953bb0..121fd4a9825df0d3770b66ed3db7a1da5a468bf8 100644 (file)
 
 #![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
index f107e1042816f4e635a9f863a7a730cf6492fdf1..7a2a4343522bb05e4ce8b062c246a3441f527793 100644 (file)
 
 #![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");
index f64bbf9312cd860351ad580e972b6c30a2772118..535ab711f5bcf62ee8803cd4c229a5809ec6775d 100644 (file)
@@ -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::{Read, Write};
 use std::process::{Command, Stdio};
 
-use rustc_back::tempdir::TempDir;
+use tempdir::TempDir;
 
 fn main() {
     if env::args().len() > 1 {
index 4542e27545a4c9768dbb1054431635b359fb5ad4..16f7e2832853663452934ebbd86f0be7dc52783c 100644 (file)
 
 #![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) {